-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
524 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
from .aliyun import Aliyun | ||
from .baidu import Baidu | ||
from .openai import OpenAI | ||
from .tencent import Tencent | ||
from .xfyun import XfYun | ||
from . import api, knowledge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .aliyun import AliyunService, AliyunModelEnum | ||
from .baidu import BaiduService, BaiduModelEnum | ||
from .moonshot import MoonshotService, MoonshotModelEnum | ||
from .openai import OpenaiService, OpenaiModelEnum | ||
from .tencent import TencentService, TencentModelEnum | ||
from .xfyun import XfYunService, XfYunModelEnum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from enum import Enum | ||
|
||
from retk import config | ||
from .openai import OpenaiLLMStyle | ||
|
||
|
||
class MoonshotModelEnum(str, Enum): | ||
V1_8K = "moonshot-v1-8k" | ||
V1_32K = "moonshot-v1-32k" | ||
V1_128K = "moonshot-v1-128k" | ||
|
||
|
||
class MoonshotService(OpenaiLLMStyle): | ||
def __init__( | ||
self, | ||
top_p: float = 0.9, | ||
temperature: float = 0.7, | ||
timeout: float = 60., | ||
): | ||
super().__init__( | ||
api_key=config.get_settings().MOONSHOT_API_KEY, | ||
endpoint="https://api.moonshot.cn/v1/chat/completions", | ||
default_model=MoonshotModelEnum.V1_8K.value, | ||
top_p=top_p, | ||
temperature=temperature, | ||
timeout=timeout, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
from typing import Tuple | ||
|
||
from retk import const | ||
from ..api.base import BaseLLMService, MessagesType | ||
|
||
system_summary_prompt = (Path(__file__).parent / "system_summary.md").read_text(encoding="utf-8") | ||
system_extend_prompt = (Path(__file__).parent / "system_extend.md").read_text(encoding="utf-8") | ||
|
||
|
||
async def _send( | ||
llm_service: BaseLLMService, | ||
model: str, | ||
system_prompt: str, | ||
query: str, | ||
req_id: str, | ||
) -> Tuple[str, const.CodeEnum]: | ||
_msgs: MessagesType = [ | ||
{"role": "system", "content": system_prompt}, | ||
{"role": "user", "content": query}, | ||
] | ||
return await llm_service.complete(messages=_msgs, model=model, req_id=req_id) | ||
|
||
|
||
async def summary( | ||
llm_service: BaseLLMService, | ||
model: str, | ||
query: str, | ||
req_id: str = None, | ||
) -> Tuple[str, const.CodeEnum]: | ||
return await _send( | ||
llm_service=llm_service, | ||
model=model, | ||
system_prompt=system_summary_prompt, | ||
query=query, | ||
req_id=req_id, | ||
) | ||
|
||
|
||
async def extend( | ||
llm_service: BaseLLMService, | ||
model: str, | ||
query: str, | ||
req_id: str = None, | ||
) -> Tuple[str, const.CodeEnum]: | ||
return await _send( | ||
llm_service=llm_service, | ||
model=model, | ||
system_prompt=system_extend_prompt, | ||
query=query, | ||
req_id=req_id, | ||
) |
Oops, something went wrong.