Update llm_handler.py
Browse files- llm_handler.py +9 -9
llm_handler.py
CHANGED
|
@@ -2,12 +2,12 @@ from openai import OpenAI
|
|
| 2 |
from params import OPENAI_MODEL, OPENAI_API_KEY
|
| 3 |
import llamanet
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
# Create an instance of the OpenAI class
|
| 6 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 7 |
|
| 8 |
-
# Initialize LlamaNet client
|
| 9 |
-
llamanet_client = llamanet.Client()
|
| 10 |
-
|
| 11 |
def send_to_chatgpt(msg_list):
|
| 12 |
try:
|
| 13 |
completion = client.chat.completions.create(
|
|
@@ -31,18 +31,18 @@ def send_to_chatgpt(msg_list):
|
|
| 31 |
|
| 32 |
def send_to_llamanet(msg_list):
|
| 33 |
try:
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
|
| 37 |
# Send request to LlamaNet
|
| 38 |
-
|
| 39 |
-
model="
|
| 40 |
-
messages=
|
| 41 |
stream=True
|
| 42 |
)
|
| 43 |
|
| 44 |
llamanet_response = ""
|
| 45 |
-
for chunk in
|
| 46 |
if chunk.choices[0].delta.content is not None:
|
| 47 |
llamanet_response += chunk.choices[0].delta.content
|
| 48 |
|
|
|
|
| 2 |
from params import OPENAI_MODEL, OPENAI_API_KEY
|
| 3 |
import llamanet
|
| 4 |
|
| 5 |
+
# Initialize LlamaNet
|
| 6 |
+
llamanet.run("start", "https://huggingface.co/arcee-ai/Arcee-Spark-GGUF/blob/main/Arcee-Spark-IQ4_XS.gguf")
|
| 7 |
+
|
| 8 |
# Create an instance of the OpenAI class
|
| 9 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
def send_to_chatgpt(msg_list):
|
| 12 |
try:
|
| 13 |
completion = client.chat.completions.create(
|
|
|
|
| 31 |
|
| 32 |
def send_to_llamanet(msg_list):
|
| 33 |
try:
|
| 34 |
+
# Create a new OpenAI client for LlamaNet (no API key needed)
|
| 35 |
+
llamanet_client = OpenAI()
|
| 36 |
|
| 37 |
# Send request to LlamaNet
|
| 38 |
+
completion = llamanet_client.chat.completions.create(
|
| 39 |
+
model="gpt-3.5-turbo", # LlamaNet uses this as a placeholder
|
| 40 |
+
messages=msg_list,
|
| 41 |
stream=True
|
| 42 |
)
|
| 43 |
|
| 44 |
llamanet_response = ""
|
| 45 |
+
for chunk in completion:
|
| 46 |
if chunk.choices[0].delta.content is not None:
|
| 47 |
llamanet_response += chunk.choices[0].delta.content
|
| 48 |
|