repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | from typing import Optional |
| #3 | |
| #4 | from langchain.schema import HumanMessage, SystemMessage |
| #5 | from langchain_community.chat_models import JinaChat |
| #6 | |
| #7 | from embedchain.config import BaseLlmConfig |
| #8 | from embedchain.helpers.json_serializable import register_deserializable |
| #9 | from embedchain.llm.base import BaseLlm |
| #10 | |
| #11 | |
| #12 | @register_deserializable |
| #13 | class JinaLlm(BaseLlm): |
| #14 | def __init__(self, config: Optional[BaseLlmConfig] = None): |
| #15 | super().__init__(config=config) |
| #16 | if not self.config.api_key and "JINACHAT_API_KEY" not in os.environ: |
| #17 | raise ValueError("Please set the JINACHAT_API_KEY environment variable or pass it in the config.") |
| #18 | |
| #19 | def get_llm_model_answer(self, prompt): |
| #20 | response = JinaLlm._get_answer(prompt, self.config) |
| #21 | return response |
| #22 | |
| #23 | @staticmethod |
| #24 | def _get_answer(prompt: str, config: BaseLlmConfig) -> str: |
| #25 | messages = [] |
| #26 | if config.system_prompt: |
| #27 | messages.append(SystemMessage(content=config.system_prompt)) |
| #28 | messages.append(HumanMessage(content=prompt)) |
| #29 | kwargs = { |
| #30 | "temperature": config.temperature, |
| #31 | "max_tokens": config.max_tokens, |
| #32 | "jinachat_api_key": config.api_key or os.environ["JINACHAT_API_KEY"], |
| #33 | "model_kwargs": {}, |
| #34 | } |
| #35 | if config.top_p: |
| #36 | kwargs["model_kwargs"]["top_p"] = config.top_p |
| #37 | if config.stream: |
| #38 | from langchain.callbacks.streaming_stdout import ( |
| #39 | StreamingStdOutCallbackHandler, |
| #40 | ) |
| #41 | |
| #42 | chat = JinaChat(**kwargs, streaming=config.stream, callbacks=[StreamingStdOutCallbackHandler()]) |
| #43 | else: |
| #44 | chat = JinaChat(**kwargs) |
| #45 | return chat(messages).content |
| #46 |