Spaces:
Build error
Build error
Commit ·
cca8811
1
Parent(s): d01bb30
llm client hf updated
Browse files- translator/llm_client.py +11 -3
translator/llm_client.py
CHANGED
|
@@ -2,13 +2,21 @@ from huggingface_hub import InferenceClient
|
|
| 2 |
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
HF_MODEL_DEFAULT = "mistralai/
|
| 6 |
OPENAI_MODEL_DEFAULT = "gpt-4o-mini"
|
| 7 |
|
|
|
|
| 8 |
def generate_with_hf(prompt, model=HF_MODEL_DEFAULT):
|
| 9 |
client = InferenceClient(model=model, token=os.getenv("HF_TOKEN"))
|
| 10 |
-
response = client.
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def generate_with_openai(prompt, model=OPENAI_MODEL_DEFAULT):
|
| 14 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
| 2 |
from openai import OpenAI
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
HF_MODEL_DEFAULT = "mistralai/Mistral-7B-Instruct-v0.3"
|
| 6 |
OPENAI_MODEL_DEFAULT = "gpt-4o-mini"
|
| 7 |
|
| 8 |
+
|
| 9 |
def generate_with_hf(prompt, model=HF_MODEL_DEFAULT):
|
| 10 |
client = InferenceClient(model=model, token=os.getenv("HF_TOKEN"))
|
| 11 |
+
response = client.chat_completion(
|
| 12 |
+
messages=[
|
| 13 |
+
{"role": "system", "content": "You are a Unity→Unreal translation expert."},
|
| 14 |
+
{"role": "user", "content": prompt},
|
| 15 |
+
],
|
| 16 |
+
max_tokens=1024,
|
| 17 |
+
temperature=0.7,
|
| 18 |
+
)
|
| 19 |
+
return response.choices[0].message["content"]
|
| 20 |
|
| 21 |
def generate_with_openai(prompt, model=OPENAI_MODEL_DEFAULT):
|
| 22 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|