mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Adds necessary spaces
Introduces spaces between code blocks.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import openai
|
||||
from config import Config
|
||||
|
||||
cfg = Config()
|
||||
|
||||
openai.api_key = cfg.openai_api_key
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
from playsound import playsound
|
||||
import requests
|
||||
from config import Config
|
||||
|
||||
cfg = Config()
|
||||
|
||||
# TODO: Nicer names for these ids
|
||||
@@ -18,8 +19,7 @@ def say_text(text, voice_index=0):
|
||||
voice_id=voices[voice_index])
|
||||
|
||||
formatted_message = {"text": text}
|
||||
response = requests.post(
|
||||
tts_url, headers=tts_headers, json=formatted_message)
|
||||
response = requests.post(tts_url, headers=tts_headers, json=formatted_message)
|
||||
|
||||
if response.status_code == 200:
|
||||
with open("speech.mpeg", "wb") as f:
|
||||
|
||||
@@ -14,6 +14,7 @@ class Spinner:
|
||||
self.running = False
|
||||
self.spinner_thread = None
|
||||
|
||||
|
||||
def spin(self):
|
||||
"""Spin the spinner"""
|
||||
while self.running:
|
||||
@@ -22,12 +23,14 @@ class Spinner:
|
||||
time.sleep(self.delay)
|
||||
sys.stdout.write('\b' * (len(self.message) + 2))
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
"""Start the spinner"""
|
||||
self.running = True
|
||||
self.spinner_thread = threading.Thread(target=self.spin)
|
||||
self.spinner_thread.start()
|
||||
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||
"""Stop the spinner"""
|
||||
self.running = False
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import tiktoken
|
||||
from typing import List, Dict
|
||||
|
||||
|
||||
def count_message_tokens(messages : List[Dict[str, str]], model : str = "gpt-3.5-turbo-0301") -> int:
|
||||
"""
|
||||
Returns the number of tokens used by a list of messages.
|
||||
@@ -17,6 +18,7 @@ def count_message_tokens(messages : List[Dict[str, str]], model : str = "gpt-3.5
|
||||
except KeyError:
|
||||
print("Warning: model not found. Using cl100k_base encoding.")
|
||||
encoding = tiktoken.get_encoding("cl100k_base")
|
||||
|
||||
if model == "gpt-3.5-turbo":
|
||||
# !Node: gpt-3.5-turbo may change over time. Returning num tokens assuming gpt-3.5-turbo-0301.")
|
||||
return count_message_tokens(messages, model="gpt-3.5-turbo-0301")
|
||||
@@ -32,15 +34,19 @@ def count_message_tokens(messages : List[Dict[str, str]], model : str = "gpt-3.5
|
||||
else:
|
||||
raise NotImplementedError(f"""num_tokens_from_messages() is not implemented for model {model}. See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens.""")
|
||||
num_tokens = 0
|
||||
|
||||
for message in messages:
|
||||
num_tokens += tokens_per_message
|
||||
|
||||
for key, value in message.items():
|
||||
num_tokens += len(encoding.encode(value))
|
||||
|
||||
if key == "name":
|
||||
num_tokens += tokens_per_name
|
||||
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
|
||||
return num_tokens
|
||||
|
||||
|
||||
def count_string_tokens(string: str, model_name: str) -> int:
|
||||
"""
|
||||
Returns the number of tokens in a text string.
|
||||
|
||||
Reference in New Issue
Block a user