diff --git a/index.html b/index.html index ece292f..b575a64 100644 --- a/index.html +++ b/index.html @@ -53,7 +53,8 @@
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