Magic_yuan commited on
Commit
0069752
·
1 Parent(s): 38d7e17

更新format

Browse files
examples/lightrag_azure_openai_demo.py CHANGED
@@ -4,7 +4,6 @@ from lightrag import LightRAG, QueryParam
4
  from lightrag.utils import EmbeddingFunc
5
  import numpy as np
6
  from dotenv import load_dotenv
7
- import aiohttp
8
  import logging
9
  from openai import AzureOpenAI
10
 
@@ -31,12 +30,12 @@ os.mkdir(WORKING_DIR)
31
 
32
 
33
  async def llm_model_func(
34
- prompt, system_prompt=None, history_messages=[], **kwargs
35
  ) -> str:
36
  client = AzureOpenAI(
37
  api_key=AZURE_OPENAI_API_KEY,
38
  api_version=AZURE_OPENAI_API_VERSION,
39
- azure_endpoint=AZURE_OPENAI_DEPLOYMENT
40
  )
41
 
42
  messages = []
@@ -47,7 +46,7 @@ async def llm_model_func(
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),
@@ -60,12 +59,9 @@ 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,
63
- azure_endpoint=AZURE_OPENAI_ENDPOINT
64
- )
65
- embedding = client.embeddings.create(
66
- model=AZURE_EMBEDDING_DEPLOYMENT,
67
- input=texts
68
  )
 
69
 
70
  embeddings = [item.embedding for item in embedding.data]
71
  return np.array(embeddings)
 
4
  from lightrag.utils import EmbeddingFunc
5
  import numpy as np
6
  from dotenv import load_dotenv
 
7
  import logging
8
  from openai import AzureOpenAI
9
 
 
30
 
31
 
32
  async def llm_model_func(
33
+ prompt, system_prompt=None, history_messages=[], **kwargs
34
  ) -> str:
35
  client = AzureOpenAI(
36
  api_key=AZURE_OPENAI_API_KEY,
37
  api_version=AZURE_OPENAI_API_VERSION,
38
+ azure_endpoint=AZURE_OPENAI_ENDPOINT,
39
  )
40
 
41
  messages = []
 
46
  messages.append({"role": "user", "content": prompt})
47
 
48
  chat_completion = client.chat.completions.create(
49
+ model=AZURE_OPENAI_DEPLOYMENT, # model = "deployment_name".
50
  messages=messages,
51
  temperature=kwargs.get("temperature", 0),
52
  top_p=kwargs.get("top_p", 1),
 
59
  client = AzureOpenAI(
60
  api_key=AZURE_OPENAI_API_KEY,
61
  api_version=AZURE_EMBEDDING_API_VERSION,
62
+ azure_endpoint=AZURE_OPENAI_ENDPOINT,
 
 
 
 
63
  )
64
+ embedding = client.embeddings.create(model=AZURE_EMBEDDING_DEPLOYMENT, input=texts)
65
 
66
  embeddings = [item.embedding for item in embedding.data]
67
  return np.array(embeddings)