kenghuoxiong commited on
Commit
144ef01
·
verified ·
1 Parent(s): 66e6749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -32,6 +32,40 @@ client = OpenAI(
32
  base_url="https://api-inference.huggingface.co/v1/",
33
  api_key=TOKEN,
34
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  embedding = load_embedding_mode()
36
  db = Chroma(persist_directory='/VecterStore2_512_txt/VecterStore2_512_txt', embedding_function=embedding)
37
  prompt_template = """
@@ -97,7 +131,7 @@ def respond(
97
  chatbot = gr.Chatbot(height=600)
98
 
99
  demo = gr.ChatInterface(
100
- respond,
101
  fill_height=True,
102
  chatbot=chatbot,
103
  additional_inputs=[
 
32
  base_url="https://api-inference.huggingface.co/v1/",
33
  api_key=TOKEN,
34
  )
35
+
36
+
37
+ def qwen_api(user_message, top_p=0.9,temperature=0.7, system_message='', max_tokens=1024, gradio_history=[]):
38
+ history = []
39
+ if gradio_history:
40
+ for message in history:
41
+ if message:
42
+ history.append({"role": "user", "content": message[0]})
43
+ history.append({"role": "assistant", "content": message[1]})
44
+
45
+ if system_message!='':
46
+ history.append({'role': 'system', 'content': system_message})
47
+ history.append({"role": "user", "content": user_message})
48
+
49
+ response = ""
50
+ for message in client.chat.completions.create(
51
+ model="meta-llama/Meta-Llama-3-8B-Instruct",
52
+ max_tokens=max_tokens,
53
+ stream=True,
54
+ temperature=temperature,
55
+ top_p=top_p,
56
+ messages=history,
57
+ ):
58
+ token = message.choices[0].delta.content
59
+ response += token
60
+ yield response
61
+ return response
62
+
63
+ llm = ChatOpenAI(
64
+ model="meta-llama/Meta-Llama-3-8B-Instruct",
65
+ temperature=0.8,)
66
+
67
+
68
+
69
  embedding = load_embedding_mode()
70
  db = Chroma(persist_directory='/VecterStore2_512_txt/VecterStore2_512_txt', embedding_function=embedding)
71
  prompt_template = """
 
131
  chatbot = gr.Chatbot(height=600)
132
 
133
  demo = gr.ChatInterface(
134
+ chat,
135
  fill_height=True,
136
  chatbot=chatbot,
137
  additional_inputs=[