Spaces:
Sleeping
Sleeping
Create utils/helper.py
Browse files- utils/helper.py +34 -0
utils/helper.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from together import Together
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
client = Together(api_key=os.environ["TOGETHER_API_KEY"])
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def call_llama(prompt: str) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Send a prompt to the Llama model and return the response.
|
| 12 |
+
Args:
|
| 13 |
+
prompt (str): The input prompt to send to the Llama model.
|
| 14 |
+
Returns:
|
| 15 |
+
str: The response from the Llama model.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
# Create a completion request with the prompt
|
| 19 |
+
response = client.chat.completions.create(
|
| 20 |
+
|
| 21 |
+
# Use the Llama-3-8b-chat-hf model
|
| 22 |
+
model="meta-llama/Llama-3-8b-chat-hf",
|
| 23 |
+
|
| 24 |
+
# Define the prompt as a user message
|
| 25 |
+
messages=[
|
| 26 |
+
{
|
| 27 |
+
"role": "user",
|
| 28 |
+
"content": prompt # Use the input prompt
|
| 29 |
+
}
|
| 30 |
+
],
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
# Return the content of the first response message
|
| 34 |
+
return response.choices[0].message.content
|