Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
import os
|
4 |
-
|
5 |
# Set your OpenAI API key
|
6 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
7 |
|
@@ -23,7 +23,7 @@ def add_file(history, file):
|
|
23 |
return history
|
24 |
|
25 |
def num_tokens_from_messages(messages, model="gpt-3.5-turbo"):
|
26 |
-
encoding =
|
27 |
num_tokens = 0
|
28 |
for message in messages:
|
29 |
num_tokens += 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
import os
|
4 |
+
import tiktoken
|
5 |
# Set your OpenAI API key
|
6 |
openai.api_key = os.getenv('OPENAI_API_KEY')
|
7 |
|
|
|
23 |
return history
|
24 |
|
25 |
def num_tokens_from_messages(messages, model="gpt-3.5-turbo"):
|
26 |
+
encoding = tiktoken.encoding_for_model(model)
|
27 |
num_tokens = 0
|
28 |
for message in messages:
|
29 |
num_tokens += 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n
|