nightfury commited on
Commit
72458cd
·
verified ·
1 Parent(s): 417ff6f

Create apppp.py

Browse files
Files changed (1) hide show
  1. apppp.py +30 -0
apppp.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from openai import OpenAI
3
+ import requests
4
+
5
+ API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
8
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
9
+
10
+ client = OpenAI(
11
+ organization=os.getenv("OPENAI_ORG_ID"), api_key=os.getenv("OPENAI_API_KEY")
12
+ )
13
+
14
+
15
+ def gpt_chatbot(user_request: str):
16
+ completion = client.chat.completions.create(
17
+ model="gpt-4o-mini",
18
+ messages=[
19
+ {"role": "system", "content": "You are a helpful assistant."},
20
+ {"role": "user", "content": user_request},
21
+ ],
22
+ )
23
+
24
+ return completion.choices[0].message.content
25
+
26
+
27
+ def llama_chatbot(user_request: str):
28
+ response = requests.post(API_URL, headers=headers, json={"inputs": user_request})
29
+
30
+ return response.json()[0]["generated_text"]