Spaces:
Running
Running
Update index.html
Browse files- index.html +14 -19
index.html
CHANGED
@@ -375,29 +375,24 @@ header:hover .scroll-indicator .arrow {
|
|
375 |
</section>
|
376 |
<section class="section">
|
377 |
<h2>Example Usage</h2>
|
378 |
-
<pre><
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
# Use the custom API endpoint
|
385 |
-
openai.api_base = "https://parthsadaria-lokiai.hf.space"
|
386 |
openai.api_key = api_key
|
387 |
-
|
388 |
-
|
389 |
-
try:
|
390 |
response = openai.ChatCompletion.create(
|
391 |
-
model="gpt-4o"
|
392 |
-
messages=[{"role": "user", "content": "hi homie"}],
|
393 |
-
stream=False
|
394 |
)
|
395 |
-
print(response['choices'][0]['message']['content'])
|
396 |
-
except Exception as e:
|
397 |
-
print(f"Error: {e}")
|
398 |
-
|
399 |
chat_with_gpt()
|
400 |
-
</
|
401 |
</section>
|
402 |
<section class="section">
|
403 |
<h2>Available Models</h2>
|
|
|
375 |
</section>
|
376 |
<section class="section">
|
377 |
<h2>Example Usage</h2>
|
378 |
+
<pre style="font-family:monospace;color: rgb(201, 209, 217); background-color: rgb(13, 17, 23); font-weight: 400; "><span style="color: rgb(255, 123, 114); font-weight: 400;">import</span> openai
|
379 |
+
<span style="color: rgb(139, 148, 158); font-weight: 400;"># hampe to he hi no :p (not needed)</span>
|
380 |
+
api_key = <span style="color: rgb(165, 214, 255); font-weight: 400;">''</span>
|
381 |
+
<span style="color: rgb(139, 148, 158); font-weight: 400;"># Use the custom API endpoint</span>
|
382 |
+
openai.api_base = <span style="color: rgb(165, 214, 255); font-weight: 400;">"https://parthsadaria-lokiai.hf.space"</span>
|
|
|
|
|
|
|
383 |
openai.api_key = api_key
|
384 |
+
<span style="color: rgb(255, 123, 114); font-weight: 400;">def</span> <span style="color: rgb(210, 168, 255); font-weight: 400;">chat_with_gpt</span>():
|
385 |
+
<span style="color: rgb(255, 123, 114); font-weight: 400;">try</span>:
|
|
|
386 |
response = openai.ChatCompletion.create(
|
387 |
+
model=<span style="color: rgb(165, 214, 255); font-weight: 400;">"gpt-4o"</span>,
|
388 |
+
messages=[{<span style="color: rgb(165, 214, 255); font-weight: 400;">"role"</span>: <span style="color: rgb(165, 214, 255); font-weight: 400;">"user"</span>, <span style="color: rgb(165, 214, 255); font-weight: 400;">"content"</span>: <span style="color: rgb(165, 214, 255); font-weight: 400;">"hi homie"</span>}],
|
389 |
+
stream=<span style="color: rgb(121, 192, 255); font-weight: 400;">False</span>
|
390 |
)
|
391 |
+
<span style="color: rgb(255, 166, 87); font-weight: 400;">print</span>(response[<span style="color: rgb(165, 214, 255); font-weight: 400;">'choices'</span>][<span style="color: rgb(121, 192, 255); font-weight: 400;">0</span>][<span style="color: rgb(165, 214, 255); font-weight: 400;">'message'</span>][<span style="color: rgb(165, 214, 255); font-weight: 400;">'content'</span>])
|
392 |
+
<span style="color: rgb(255, 123, 114); font-weight: 400;">except</span> Exception <span style="color: rgb(255, 123, 114); font-weight: 400;">as</span> e:
|
393 |
+
<span style="color: rgb(255, 166, 87); font-weight: 400;">print</span>(<span style="color: rgb(165, 214, 255); font-weight: 400;">f"Error: <span style="color: rgb(201, 209, 217); font-weight: 400;">{e}</span>"</span>)
|
|
|
394 |
chat_with_gpt()
|
395 |
+
</pre>
|
396 |
</section>
|
397 |
<section class="section">
|
398 |
<h2>Available Models</h2>
|