Magic_yuan
commited on
Commit
·
58c112a
1
Parent(s):
5570390
Update lightrag_azure_openai_demo.py
Browse files
examples/lightrag_azure_openai_demo.py
CHANGED
@@ -31,13 +31,12 @@ os.mkdir(WORKING_DIR)
|
|
31 |
|
32 |
|
33 |
async def llm_model_func(
|
34 |
-
|
35 |
) -> str:
|
36 |
-
|
37 |
client = AzureOpenAI(
|
38 |
-
api_key=
|
39 |
-
api_version=
|
40 |
-
azure_endpoint=
|
41 |
)
|
42 |
|
43 |
messages = []
|
@@ -48,7 +47,7 @@ async def llm_model_func(
|
|
48 |
messages.append({"role": "user", "content": prompt})
|
49 |
|
50 |
chat_completion = client.chat.completions.create(
|
51 |
-
model=
|
52 |
messages=messages,
|
53 |
temperature=kwargs.get("temperature", 0),
|
54 |
top_p=kwargs.get("top_p", 1),
|
@@ -58,7 +57,6 @@ async def llm_model_func(
|
|
58 |
|
59 |
|
60 |
async def embedding_func(texts: list[str]) -> np.ndarray:
|
61 |
-
|
62 |
client = AzureOpenAI(
|
63 |
api_key=AZURE_OPENAI_API_KEY,
|
64 |
api_version=AZURE_EMBEDDING_API_VERSION,
|
@@ -68,7 +66,7 @@ async def embedding_func(texts: list[str]) -> np.ndarray:
|
|
68 |
model=AZURE_EMBEDDING_DEPLOYMENT,
|
69 |
input=texts
|
70 |
)
|
71 |
-
|
72 |
embeddings = [item.embedding for item in embedding.data]
|
73 |
return np.array(embeddings)
|
74 |
|
|
|
31 |
|
32 |
|
33 |
async def llm_model_func(
|
34 |
+
prompt, system_prompt=None, history_messages=[], **kwargs
|
35 |
) -> str:
|
|
|
36 |
client = AzureOpenAI(
|
37 |
+
api_key=LLM_AZURE_OPENAI_KEY,
|
38 |
+
api_version=LLM_AZURE_OPENAI_VERSION,
|
39 |
+
azure_endpoint=LLM_AZURE_OPENAI_API
|
40 |
)
|
41 |
|
42 |
messages = []
|
|
|
47 |
messages.append({"role": "user", "content": prompt})
|
48 |
|
49 |
chat_completion = client.chat.completions.create(
|
50 |
+
model=LLM_AZURE_OPENAI_DEPLOYMENT, # model = "deployment_name".
|
51 |
messages=messages,
|
52 |
temperature=kwargs.get("temperature", 0),
|
53 |
top_p=kwargs.get("top_p", 1),
|
|
|
57 |
|
58 |
|
59 |
async def embedding_func(texts: list[str]) -> np.ndarray:
|
|
|
60 |
client = AzureOpenAI(
|
61 |
api_key=AZURE_OPENAI_API_KEY,
|
62 |
api_version=AZURE_EMBEDDING_API_VERSION,
|
|
|
66 |
model=AZURE_EMBEDDING_DEPLOYMENT,
|
67 |
input=texts
|
68 |
)
|
69 |
+
|
70 |
embeddings = [item.embedding for item in embedding.data]
|
71 |
return np.array(embeddings)
|
72 |
|