From a5d4bb88e07ba608176d8c37efcd1f6452cb9e96 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 14 Oct 2024 22:44:20 +0000 Subject: [PATCH] modified: index.html --- index.html | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index ece292f..b575a64 100644 --- a/index.html +++ b/index.html @@ -53,7 +53,8 @@

Python Example

Non-Streaming

-
from openai import OpenAI
+    

+from openai import OpenAI
 
 client = OpenAI(base_url="https://hermes.ai.unturf.com/v1", api_key="none")
 
@@ -76,7 +77,8 @@ print(response.choices[0].message.content)
     

Streaming

-
from openai import OpenAI
+    

+from openai import OpenAI
 
 client = OpenAI(base_url="https://hermes.ai.unturf.com/v1", api_key="none")
 
@@ -84,7 +86,9 @@ client = OpenAI(base_url="https://hermes.ai.unturf.com/v1", api_key="none")
 MODEL = "NousResearch/Hermes-3-Llama-3.1-8B"
 
 # Define your messages
-messages = [{"role": "user", "content": "Give a Python Fizzbuzz solution in one line of code?"}]
+messages = [
+    {"role": "user", "content": "Give a Python Fizzbuzz solution in one line of code?"}
+]
 
 # Make the streaming request
 response = client.chat.completions.create(
@@ -92,12 +96,14 @@ response = client.chat.completions.create(
     messages=messages,
     temperature=0.5,
     max_tokens=150,
-    stream=True  # Enable streaming
+    stream=True,  # Enable streaming
 )
 
 # Print each message in the streaming response
-for msg in response:
-    print(msg['choices'][0]['delta']['content'], end='')
+for chunk in response:
+    # The 'ChatCompletionChunk' object exposes the 'choices' attribute directly
+    if hasattr(chunk.choices[0].delta, "content"):
+        print(chunk.choices[0].delta.content, end="")
     

Node.js Example