更新Azure API版本

master
落雨楓 2 years ago
parent 10de406b2d
commit 2a1e5c1589

@ -1,43 +0,0 @@
import asyncio
import asyncpg
import os
from config import Config
conn = None
class Install:
dbi: asyncpg.Connection
async def run(self):
db_config = Config.get("database")
self.dbi = await asyncpg.connect(db_config)
args = os.sys.argv
if "--force" in args:
await self.drop_table()
await self.create_table()
async def drop_table(self):
await self.dbi.execute("DROP TABLE IF EXISTS embedding_search_title_index;")
print("Table dropped")
async def create_table(self):
embedding_vector_size = Config.get("chatcomplete.embedding_vector_size", 512, int)
await self.dbi.execute("""
CREATE TABLE embedding_search_title_index (
id SERIAL PRIMARY KEY,
sha1 VARCHAR(40) NOT NULL UNIQUE,
title TEXT NOT NULL,
rev_id INT8 NOT NULL,
embedding VECTOR(%d) NOT NULL
);
""" % (embedding_vector_size))
await self.dbi.execute("CREATE INDEX embedding_search_title_index_embedding_idx ON embedding_search_title_index USING ivfflat (embedding vector_cosine_ops);")
print("Table created")
if __name__ == "__main__":
install = Install()
loop = asyncio.get_event_loop()
loop.run_until_complete(install.run())

@ -15,7 +15,6 @@ from config import Config
import utils.config, utils.web import utils.config, utils.web
from aiohttp import web from aiohttp import web
from api.model.embedding_search.title_collection import TitleCollectionModel
from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.orm.attributes import flag_modified
from service.database import DatabaseService from service.database import DatabaseService

@ -10,6 +10,9 @@ from aiohttp_sse_client2 import client as sse_client
from service.tiktoken import TikTokenService from service.tiktoken import TikTokenService
AZURE_CHATCOMPLETE_API_VERSION = "2023-07-01-preview"
AZURE_EMBEDDING_API_VERSION = "2023-05-15"
class ChatCompleteMessageLog(TypedDict): class ChatCompleteMessageLog(TypedDict):
role: str role: str
content: str content: str
@ -89,7 +92,7 @@ class OpenAIApi:
} }
if self.api_type == "azure": if self.api_type == "azure":
params["api-version"] = "2023-05-15" params["api-version"] = AZURE_EMBEDDING_API_VERSION
else: else:
post_data["model"] = "text-embedding-ada-002" post_data["model"] = "text-embedding-ada-002"
@ -190,7 +193,7 @@ class OpenAIApi:
} }
if self.api_type == "azure": if self.api_type == "azure":
params["api-version"] = "2023-05-15" params["api-version"] = AZURE_CHATCOMPLETE_API_VERSION
else: else:
post_data["model"] = "gpt-3.5-turbo" post_data["model"] = "gpt-3.5-turbo"
@ -248,7 +251,7 @@ class OpenAIApi:
} }
if self.api_type == "azure": if self.api_type == "azure":
params["api-version"] = "2023-05-15" params["api-version"] = AZURE_CHATCOMPLETE_API_VERSION
else: else:
post_data["model"] = "gpt-3.5-turbo" post_data["model"] = "gpt-3.5-turbo"

Loading…
Cancel
Save