mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
3241e4015b
Co-authored-by: jyong <718720800@qq.com>
33 lines
901 B
Python
33 lines
901 B
Python
import os
|
|
from typing import Optional
|
|
|
|
import langchain
|
|
from flask import Flask
|
|
from langchain.prompts.base import DEFAULT_FORMATTER_MAPPING
|
|
from pydantic import BaseModel
|
|
|
|
from core.callback_handler.std_out_callback_handler import DifyStdOutCallbackHandler
|
|
from core.prompt.prompt_template import OneLineFormatter
|
|
|
|
|
|
class HostedOpenAICredential(BaseModel):
|
|
api_key: str
|
|
|
|
|
|
class HostedLLMCredentials(BaseModel):
|
|
openai: Optional[HostedOpenAICredential] = None
|
|
|
|
|
|
hosted_llm_credentials = HostedLLMCredentials()
|
|
|
|
|
|
def init_app(app: Flask):
|
|
formatter = OneLineFormatter()
|
|
DEFAULT_FORMATTER_MAPPING['f-string'] = formatter.format
|
|
|
|
if os.environ.get("DEBUG") and os.environ.get("DEBUG").lower() == 'true':
|
|
langchain.verbose = True
|
|
|
|
if app.config.get("OPENAI_API_KEY"):
|
|
hosted_llm_credentials.openai = HostedOpenAICredential(api_key=app.config.get("OPENAI_API_KEY"))
|