Skip to content

Commit

Permalink
Merge branch 'master' of github.com:chatchat-space/LangGraph-Chatchat…
Browse files Browse the repository at this point in the history
… into feature/api
  • Loading branch information
yuehuazhang committed Jan 6, 2025
2 parents e946e61 + c16a156 commit 2ea07e9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Grade(BaseModel):
If the document contains keyword(s) or semantic meaning related to the user question, grade it as relevant.
Give a binary score 'yes' or 'no' score to indicate whether the document is relevant to the question.
The format of output must be an object contains attribute of 'binary_score', like: '{{"binary_score": "yes"}}.'
""",
input_variables=["docs", "history"],
)
Expand All @@ -175,7 +176,7 @@ class Grade(BaseModel):
logger.warning(f"The scored_result is None. Defaulting to 'yes'. Question: {state['question']}")
score = "yes"
else:
score = scored_result.binary_score
score = scored_result.binary_score if hasattr(scored_result, "binary_score") else None

if score == "yes":
return "generate"
Expand Down
8 changes: 4 additions & 4 deletions chatchat-server/chatchat/server/localai_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from langchain_community.utils.openai import is_openai_v1
from langchain_core.embeddings import Embeddings
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
from pydantic import BaseModel, Field, model_validator
from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names
from tenacity import (
AsyncRetrying,
Expand Down Expand Up @@ -171,9 +171,9 @@ class LocalAIEmbeddings(BaseModel, Embeddings):
class Config:
"""Configuration for this pydantic object."""

allow_population_by_field_name = True
populate_by_name = True

@root_validator(pre=True)
@model_validator(mode='before')
def build_extra(cls, values: Dict[str, Any]) -> Dict[str, Any]:
"""Build extra kwargs from additional params that were passed in."""
all_required_field_names = get_pydantic_field_names(cls)
Expand All @@ -199,7 +199,7 @@ def build_extra(cls, values: Dict[str, Any]) -> Dict[str, Any]:
values["model_kwargs"] = extra
return values

@root_validator()
@model_validator(mode='after')
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key and python package exists in environment."""
values["openai_api_key"] = get_from_dict_or_env(
Expand Down
2 changes: 1 addition & 1 deletion chatchat-server/chatchat/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def get_Embeddings(
embed_model: str = None,
local_wrap: bool = False, # use local wrapped api
) -> Embeddings:
from langchain_community.embeddings import OllamaEmbeddings
from langchain_ollama import OllamaEmbeddings
from langchain_openai import OpenAIEmbeddings

from chatchat.server.localai_embeddings import (
Expand Down
18 changes: 12 additions & 6 deletions chatchat-server/chatchat/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
except:
pass

# 多进程之前配置LangSmith使之生效
try:
from chatchat.settings import Settings

if Settings.basic_settings.LANG_SMITH["OPEN_LANGSMITH"] is True:
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGSMITH_API_KEY"] = Settings.basic_settings.LANG_SMITH["LANGCHAIN_API_KEY"]
os.environ["LANGCHAIN_PROJECT"] = Settings.basic_settings.LANG_SMITH["LANGCHAIN_PROJECT"]
print(f"LANG_SMITH CONFIG: {Settings.basic_settings.LANG_SMITH}")
except:
pass

import click

from fastapi import FastAPI
Expand Down Expand Up @@ -67,12 +79,6 @@ def run_api_server(
)
logging.config.dictConfig(logging_conf) # type: ignore

if Settings.basic_settings.LANG_SMITH["OPEN_LANGSMITH"] is True:
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGSMITH_API_KEY"] = Settings.basic_settings.LANG_SMITH["LANGCHAIN_API_KEY"]
os.environ["LANGCHAIN_PROJECT"] = Settings.basic_settings.LANG_SMITH["LANGCHAIN_PROJECT"]
logger.info(f"LANG_SMITH CONFIG: {Settings.basic_settings.LANG_SMITH}")

uvicorn.run(app, host=host, port=port)


Expand Down
1 change: 1 addition & 0 deletions chatchat-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ psycopg-pool = "^3.2.3"
langgraph-checkpoint-postgres = "^2.0.2"
setuptools = {version = "^75.5.0", allow-prereleases = true}
pymilvus = "^2.4.9"
langchain-ollama = ">=0.2,<0.3"
[tool.poetry.extras]
xinference = ["xinference_client"]
zhipuai = ["zhipuai"]
Expand Down
Binary file removed docs/img/qr_code_116_3.jpg
Binary file not shown.
Binary file modified docs/img/wx_01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2ea07e9

Please sign in to comment.