modified: index.html
This commit is contained in:
parent
2c7f0c4420
commit
a5d4bb88e0
1 changed files with 12 additions and 6 deletions
18
index.html
18
index.html
|
|
@ -53,7 +53,8 @@
|
|||
|
||||
<h2>Python Example</h2>
|
||||
<h3>Non-Streaming</h3>
|
||||
<pre><code>from openai import OpenAI
|
||||
<pre><code>
|
||||
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)
|
|||
</code></pre>
|
||||
|
||||
<h3>Streaming</h3>
|
||||
<pre><code>from openai import OpenAI
|
||||
<pre><code>
|
||||
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="")
|
||||
</code></pre>
|
||||
|
||||
<h2>Node.js Example</h2>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue