trying new things out again
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import requests
|
|
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 |
-
client = InferenceClient("
|
12 |
|
13 |
|
14 |
|
@@ -34,19 +34,19 @@ def respond(
|
|
34 |
|
35 |
messages.append({"role": "user", "content": message})
|
36 |
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
|
51 |
### doesn't work
|
52 |
# input_ids = tokenizer.encode(message, return_tensors = 'pt')
|
@@ -54,14 +54,14 @@ def respond(
|
|
54 |
# output_text = tokenizer.decode(output, skip_special_tokens=True)
|
55 |
# yield output_text
|
56 |
|
57 |
-
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
58 |
-
headers = {"Authorization": "Bearer "+os.environ['hf_token']}
|
59 |
-
response = requests.post(API_URL, headers=headers, json={"inputs":message})
|
60 |
-
data = response.json()
|
61 |
-
returnval = ""
|
62 |
-
for item in data:
|
63 |
-
|
64 |
-
|
65 |
|
66 |
|
67 |
|
|
|
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 |
+
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
12 |
|
13 |
|
14 |
|
|
|
34 |
|
35 |
messages.append({"role": "user", "content": message})
|
36 |
|
37 |
+
response = ""
|
38 |
|
39 |
+
for message in client.chat_completion(
|
40 |
+
messages,
|
41 |
+
max_tokens=max_tokens,
|
42 |
+
stream=True,
|
43 |
+
temperature=temperature,
|
44 |
+
top_p=top_p,
|
45 |
+
):
|
46 |
+
token = message.choices[0].delta.content
|
47 |
|
48 |
+
response += token
|
49 |
+
yield response
|
50 |
|
51 |
### doesn't work
|
52 |
# input_ids = tokenizer.encode(message, return_tensors = 'pt')
|
|
|
54 |
# output_text = tokenizer.decode(output, skip_special_tokens=True)
|
55 |
# yield output_text
|
56 |
|
57 |
+
# API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
58 |
+
# headers = {"Authorization": "Bearer "+os.environ['hf_token']}
|
59 |
+
# response = requests.post(API_URL, headers=headers, json={"inputs":message})
|
60 |
+
# data = response.json()
|
61 |
+
# returnval = ""
|
62 |
+
# for item in data:
|
63 |
+
# returnval = returnval + item['generated_text']
|
64 |
+
# yield returnval
|
65 |
|
66 |
|
67 |
|