1.安装环境(建议使用python3.9以及以上版本)
gradio==3.31.0
langchain==0.0.173
loguru==0.5.3
moviepy==1.0.3
openai==0.27.6
openai_whisper==20230314
pandas==1.3.4
pymongo==3.12.1
requests==2.28.1
retry==0.9.2
tqdm==4.65.0
whisper==1.1.10
redis
pymongo==3.12.1
2.简单实用
import os
import openai
from langchain.chat_models import AzureChatOpenAI
from langchain import PromptTemplate, LLMChain
from common.logUtil_2 import log_debug
API_KEY = "sk-"
AZURE_OPENAI_API_KEY = "xxxxxx" # azure
AZURE_OPENAI_BASE_URL = "https://openaiyj.openai.azure.com/"
AZURE_OPENAI_AREA = "eastus"
AZURE_DEPLOYMENT_NAME = "gpt3"
AZURE_EMBEDDING_DEPLOYMENT_NAME = "embedding"
AZURE_API_VERSION = "2023-03-15-preview"
AZURE_API_TYPE = "azure"
AZURE_API_TEMPERATRUE = 0.3
def setup_llm_azure():
"""
创建返回langchain azure的ChatOpenAI对象
:return:
"""
chat = AzureChatOpenAI(
openai_api_base=AZURE_OPENAI_BASE_URL,
openai_api_version=AZURE_API_VERSION,
deployment_name=AZURE_DEPLOYMENT_NAME,
openai_api_key=AZURE_OPENAI_API_KEY,
openai_api_type=AZURE_API_TYPE,
temperature=AZURE_API_TEMPERATRUE
)
return chat
TEXT_PROMPT = '''
提示内容
{变量1}{变量2}
'''
#使用方法一
async def checkup_report_format(text: str):
"""
整理ocr提炼出的文本
"""
llm = setup_llm_azure()
prompt = PromptTemplate(template=TEXT_PROMPT, input_variables=["变量1"])
#多个变量
#prompt = PromptTemplate(template=TEXT_PROMPT, input_variables=["变量1", "变量2"])
chain = LLMChain(llm=llm, prompt=prompt, output_key="result", verbose=True)
result = None
try:
log_info("开始识别")
print(text)
result = await chain.arun(text)
#多个变量
#result = await chain.arun({"变量1": xxxx, "变量2": xxxx})
log_info(f"结束识别-{result}")
return result
except Exception as e:
log_error(f"checkup_result_format error:{e}")
return result
if __name__ == '__main__':
asyncio.run(checkup_report_format())
标签:变量,azure,AZURE,API,openai,result,使用,gpt,关于
From: https://www.cnblogs.com/pythonywy/p/17733138.html