nanova commited on
Commit
da03023
·
1 Parent(s): 2f7c5ff

feat: update llm model to api

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -1,11 +1,13 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
 
 
 
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
-
9
 
10
  def respond(
11
  message,
@@ -25,19 +27,35 @@ def respond(
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
 
38
 
39
- response += token
40
- yield response
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  """
@@ -52,7 +70,7 @@ demo = gr.ChatInterface(
52
  gr.Slider(
53
  minimum=0.1,
54
  maximum=1.0,
55
- value=0.95,
56
  step=0.05,
57
  label="Top-p (nucleus sampling)",
58
  ),
 
1
  import gradio as gr
2
+ import requests
3
+ import json
4
+
5
+ API_URL = "https://api.whaleflux.com/whaleflux/v1/model/deployment/enova-service-8fbf8085-2d13-4583/v1/chat/completions"
6
+ API_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiJNVGMwTlRVMk5EVTROaTR4T0dNd01qUXpaVEJsTVRsaVpURmhPV1V5TkdVMk9UUTRabVppTjJNME16RmtaVGt4WkRjM056RmtPR1l4TTJFek1HRmpNek15WW1JMFlUTmpPVEUwIiwiaWF0IjoxNzQ1NTY0NTg2LCJleHAiOi0xLCJvcmdfaWQiOiIxMDAyNzA5NSIsInNjb3BlIjp7InBlcm1pc3Npb24iOm51bGx9LCJ0eXBlIjoiYXBpLXRva2VuIiwiTWFwQ2xhaW1zIjpudWxsfQ.fw6eZmOWr7gBqKd6X5duGao0MOimZ69Fv0oeBVWy0Gk"
7
 
8
  """
9
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
10
  """
 
 
11
 
12
  def respond(
13
  message,
 
27
 
28
  messages.append({"role": "user", "content": message})
29
 
30
+ headers = {
31
+ "Content-Type": "application/json",
32
+ "Authorization": f"Bearer {API_TOKEN}"
33
+ }
34
 
35
+ data = {
36
+ "model": "/data/DMind-1-mini",
37
+ "stream": True,
38
+ "messages": messages,
39
+ "temperature": temperature,
40
+ "top_p": top_p,
41
+ "top_k": 20,
42
+ "min_p": 0.1
43
+ }
44
 
45
+ response = ""
46
+
47
+ with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
48
+ for line in r.iter_lines():
49
+ if line:
50
+ try:
51
+ json_response = json.loads(line.decode('utf-8').replace('data: ', ''))
52
+ if 'choices' in json_response and len(json_response['choices']) > 0:
53
+ token = json_response['choices'][0].get('delta', {}).get('content', '')
54
+ if token:
55
+ response += token
56
+ yield response
57
+ except json.JSONDecodeError:
58
+ continue
59
 
60
 
61
  """
 
70
  gr.Slider(
71
  minimum=0.1,
72
  maximum=1.0,
73
+ value=0.96,
74
  step=0.05,
75
  label="Top-p (nucleus sampling)",
76
  ),