feat: ichat 修改LLM 的接口
This commit is contained in:
parent
8f6a6eb973
commit
c0277ad9a6
|
@ -1,12 +1,8 @@
|
||||||
|
|
||||||
|
from django.urls import path
|
||||||
from apps.ichat.views import QueryLLMview
|
from apps.ichat.views import QueryLLMview
|
||||||
from django.urls import path, include
|
|
||||||
from rest_framework.routers import DefaultRouter
|
|
||||||
|
|
||||||
API_BASE_URL = 'api/hrm/'
|
API_BASE_URL = 'api/llm/ichat/'
|
||||||
HTML_BASE_URL = 'dhtml/hrm/'
|
|
||||||
|
|
||||||
router = DefaultRouter()
|
|
||||||
router.register('llm/query/', QueryLLMview, basename='llm_query')
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(API_BASE_URL, include(router.urls)),
|
path(API_BASE_URL + 'query/', QueryLLMview.as_view(), name='llm_query'),
|
||||||
]
|
]
|
|
@ -1,23 +1,20 @@
|
||||||
import requests
|
import requests
|
||||||
from pydantic import Field
|
|
||||||
from langchain_core.language_models import LLM
|
from langchain_core.language_models import LLM
|
||||||
from langchain_core.outputs import LLMResult, Generation
|
from langchain_core.outputs import LLMResult, Generation
|
||||||
from langchain_experimental.sql import SQLDatabaseChain
|
from langchain_experimental.sql import SQLDatabaseChain
|
||||||
from langchain_community.utilities import SQLDatabase
|
from langchain_community.utilities import SQLDatabase
|
||||||
from server.conf import DATABASES
|
from server.conf import DATABASES
|
||||||
from serializers import CustomLLMrequestSerializer
|
from apps.ichat.serializers import CustomLLMrequestSerializer
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
# fastapi
|
from rest_framework.response import Response
|
||||||
from fastapi import FastAPI
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
|
|
||||||
db_conf = DATABASES['default']
|
db_conf = DATABASES['default']
|
||||||
# 密码需要 URL 编码(因为有特殊字符如 @)
|
# 密码需要 URL 编码(因为有特殊字符如 @)
|
||||||
password_encodeed = quote_plus(db_conf['password'])
|
password_encodeed = quote_plus(db_conf['PASSWORD'])
|
||||||
|
|
||||||
db = SQLDatabase.from_uri(f"postgresql+psycopg2://{db_conf['user']}:{password_encodeed}@{db_conf['host']}/{db_conf['name']}", include_tables=["enm_mpoint", "enm_mpointstat"])
|
db = SQLDatabase.from_uri(f"postgresql+psycopg2://{db_conf['USER']}:{password_encodeed}@{db_conf['HOST']}/{db_conf['NAME']}", include_tables=["enm_mpoint", "enm_mpointstat"])
|
||||||
# model_url = "http://14.22.88.72:11025/v1/chat/completions"
|
# model_url = "http://14.22.88.72:11025/v1/chat/completions"
|
||||||
model_url = "http://139.159.180.64:11434/v1/chat/completions"
|
model_url = "http://139.159.180.64:11434/v1/chat/completions"
|
||||||
|
|
||||||
|
@ -74,6 +71,6 @@ class QueryLLMview(APIView):
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
prompt = serializer.validated_data['prompt']
|
prompt = serializer.validated_data['prompt']
|
||||||
llm = CustomLLM(model_url=model_url)
|
llm = CustomLLM(model_url=model_url)
|
||||||
chain = SQLDatabaseChain(llm=llm, database=db, verbose=True)
|
chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)
|
||||||
result = chain.invoke(prompt)
|
result = chain.invoke(prompt)
|
||||||
return result
|
return Response({"result": result})
|
|
@ -126,7 +126,7 @@ class WMaterial(CommonBDModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mat_in_qs(cls, mtask: Mtask, qs=None):
|
def mat_in_qs(cls, mtask: Mtask, qs=None):
|
||||||
"""
|
"""
|
||||||
可用于该子任务的queryset
|
TN: 可用于该子任务的queryset
|
||||||
"""
|
"""
|
||||||
if qs is None:
|
if qs is None:
|
||||||
qs = cls.objects
|
qs = cls.objects
|
||||||
|
|
|
@ -44,6 +44,7 @@ urlpatterns = [
|
||||||
|
|
||||||
# api
|
# api
|
||||||
path('', include('apps.auth1.urls')),
|
path('', include('apps.auth1.urls')),
|
||||||
|
path('', include('apps.ichat.urls')),
|
||||||
path('', include('apps.system.urls')),
|
path('', include('apps.system.urls')),
|
||||||
path('', include('apps.monitor.urls')),
|
path('', include('apps.monitor.urls')),
|
||||||
path('', include('apps.wf.urls')),
|
path('', include('apps.wf.urls')),
|
||||||
|
|
Loading…
Reference in New Issue