mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 07:16:04 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd10db3c75 | ||
|
|
db4c658980 | ||
|
|
0ee88674f8 | ||
|
|
3540759682 | ||
|
|
44cc8f15b4 | ||
|
|
59f821bf0a | ||
|
|
80858672b0 | ||
|
|
3258d5b255 |
42
.github/workflows/build-docker-image.yml
vendored
42
.github/workflows/build-docker-image.yml
vendored
@@ -17,22 +17,32 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [ -z "$GITHUB_REF" ]; then
|
if [ -z "$GITHUB_REF" ]; then
|
||||||
export GITHUB_REF=${{ github.ref }}
|
export GITHUB_REF=${{ github.ref }}
|
||||||
|
echo $GITHUB_REF
|
||||||
|
fi
|
||||||
|
# - name: Check GITHUB_REF env
|
||||||
|
# run: echo $GITHUB_REF
|
||||||
|
# - name: Get version # 在 GitHub Actions 运行环境
|
||||||
|
# id: get_version
|
||||||
|
# if: (startsWith(env.GITHUB_REF, 'refs/tags/')||startsWith(github.ref, 'refs/tags/')) && startsWith(github.repository, 'RockChinQ/QChatGPT')
|
||||||
|
# run: export GITHUB_REF=${GITHUB_REF/refs\/tags\//}
|
||||||
|
- name: Check version
|
||||||
|
id: check_version
|
||||||
|
run: |
|
||||||
|
echo $GITHUB_REF
|
||||||
|
# 如果是tag,则去掉refs/tags/前缀
|
||||||
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||||
|
echo "It's a tag"
|
||||||
|
echo $GITHUB_REF
|
||||||
|
echo $GITHUB_REF | awk -F '/' '{print $3}'
|
||||||
|
echo ::set-output name=version::$(echo $GITHUB_REF | awk -F '/' '{print $3}')
|
||||||
|
else
|
||||||
|
echo "It's not a tag"
|
||||||
|
echo $GITHUB_REF
|
||||||
|
echo ::set-output name=version::${GITHUB_REF}
|
||||||
fi
|
fi
|
||||||
- name: Check GITHUB_REF env
|
|
||||||
run: echo $GITHUB_REF
|
|
||||||
- name: Get version
|
|
||||||
id: get_version
|
|
||||||
if: (startsWith(env.GITHUB_REF, 'refs/tags/')||startsWith(github.ref, 'refs/tags/')) && startsWith(github.repository, 'RockChinQ/QChatGPT')
|
|
||||||
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
|
||||||
- name: Build # image name: rockchin/qchatgpt:<VERSION>
|
|
||||||
run: docker build --network=host -t rockchin/qchatgpt:${{ steps.get_version.outputs.VERSION }} -t rockchin/qchatgpt:latest .
|
|
||||||
- name: Login to Registry
|
- name: Login to Registry
|
||||||
run: docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
|
run: docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
- name: Create Buildx
|
||||||
- name: Push image
|
run: docker buildx create --name mybuilder --use
|
||||||
if: (startsWith(env.GITHUB_REF, 'refs/tags/')||startsWith(github.ref, 'refs/tags/')) && startsWith(github.repository, 'RockChinQ/QChatGPT')
|
- name: Build # image name: rockchin/qchatgpt:<VERSION>
|
||||||
run: docker push rockchin/qchatgpt:${{ steps.get_version.outputs.VERSION }}
|
run: docker buildx build --platform linux/arm64,linux/amd64 -t rockchin/qchatgpt:${{ steps.check_version.outputs.version }} -t rockchin/qchatgpt:latest . --push
|
||||||
|
|
||||||
- name: Push latest image
|
|
||||||
if: (startsWith(env.GITHUB_REF, 'refs/tags/')||startsWith(github.ref, 'refs/tags/')) && startsWith(github.repository, 'RockChinQ/QChatGPT')
|
|
||||||
run: docker push rockchin/qchatgpt:latest
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN python -m pip install -r requirements.txt
|
RUN apt update \
|
||||||
|
&& apt install gcc -y \
|
||||||
|
&& python -m pip install -r requirements.txt
|
||||||
|
|
||||||
CMD [ "python", "main.py" ]
|
CMD [ "python", "main.py" ]
|
||||||
@@ -23,3 +23,12 @@ class MessageHandler(metaclass=abc.ABCMeta):
|
|||||||
query: core_entities.Query,
|
query: core_entities.Query,
|
||||||
) -> entities.StageProcessResult:
|
) -> entities.StageProcessResult:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def cut_str(self, s: str) -> str:
|
||||||
|
"""
|
||||||
|
取字符串第一行,最多20个字符,若有多行,或超过20个字符,则加省略号
|
||||||
|
"""
|
||||||
|
s0 = s.split('\n')[0]
|
||||||
|
if len(s0) > 20 or '\n' in s:
|
||||||
|
s0 = s0[:20] + '...'
|
||||||
|
return s0
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ class ChatMessageHandler(handler.MessageHandler):
|
|||||||
async for result in query.use_model.requester.request(query):
|
async for result in query.use_model.requester.request(query):
|
||||||
query.resp_messages.append(result)
|
query.resp_messages.append(result)
|
||||||
|
|
||||||
|
self.ap.logger.info(f'对话({query.query_id})响应: {self.cut_str(result.readable_str())}')
|
||||||
|
|
||||||
if result.content is not None:
|
if result.content is not None:
|
||||||
text_length += len(result.content)
|
text_length += len(result.content)
|
||||||
|
|
||||||
@@ -86,6 +88,9 @@ class ChatMessageHandler(handler.MessageHandler):
|
|||||||
new_query=query
|
new_query=query
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
||||||
|
self.ap.logger.error(f'对话({query.query_id})请求失败: {str(e)}')
|
||||||
|
|
||||||
yield entities.StageProcessResult(
|
yield entities.StageProcessResult(
|
||||||
result_type=entities.ResultType.INTERRUPT,
|
result_type=entities.ResultType.INTERRUPT,
|
||||||
new_query=query,
|
new_query=query,
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ class CommandHandler(handler.MessageHandler):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.ap.logger.info(f'命令({query.query_id})报错: {self.cut_str(str(ret.error))}')
|
||||||
|
|
||||||
yield entities.StageProcessResult(
|
yield entities.StageProcessResult(
|
||||||
result_type=entities.ResultType.CONTINUE,
|
result_type=entities.ResultType.CONTINUE,
|
||||||
new_query=query
|
new_query=query
|
||||||
@@ -106,6 +108,8 @@ class CommandHandler(handler.MessageHandler):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.ap.logger.info(f'命令返回: {self.cut_str(ret.text)}')
|
||||||
|
|
||||||
yield entities.StageProcessResult(
|
yield entities.StageProcessResult(
|
||||||
result_type=entities.ResultType.CONTINUE,
|
result_type=entities.ResultType.CONTINUE,
|
||||||
new_query=query
|
new_query=query
|
||||||
|
|||||||
@@ -34,7 +34,12 @@ class Processor(stage.PipelineStage):
|
|||||||
|
|
||||||
self.ap.logger.info(f"处理 {query.launcher_type.value}_{query.launcher_id} 的请求({query.query_id}): {message_text}")
|
self.ap.logger.info(f"处理 {query.launcher_type.value}_{query.launcher_id} 的请求({query.query_id}): {message_text}")
|
||||||
|
|
||||||
if message_text.startswith('!') or message_text.startswith('!'):
|
async def generator():
|
||||||
return self.cmd_handler.handle(query)
|
if message_text.startswith('!') or message_text.startswith('!'):
|
||||||
else:
|
async for result in self.cmd_handler.handle(query):
|
||||||
return self.chat_handler.handle(query)
|
yield result
|
||||||
|
else:
|
||||||
|
async for result in self.chat_handler.handle(query):
|
||||||
|
yield result
|
||||||
|
|
||||||
|
return generator()
|
||||||
|
|||||||
@@ -31,3 +31,13 @@ class Message(pydantic.BaseModel):
|
|||||||
tool_calls: typing.Optional[list[ToolCall]] = None
|
tool_calls: typing.Optional[list[ToolCall]] = None
|
||||||
|
|
||||||
tool_call_id: typing.Optional[str] = None
|
tool_call_id: typing.Optional[str] = None
|
||||||
|
|
||||||
|
def readable_str(self) -> str:
|
||||||
|
if self.content is not None:
|
||||||
|
return self.content
|
||||||
|
elif self.function_call is not None:
|
||||||
|
return f'{self.function_call.name}({self.function_call.arguments})'
|
||||||
|
elif self.tool_calls is not None:
|
||||||
|
return f'调用工具: {self.tool_calls[0].id}'
|
||||||
|
else:
|
||||||
|
return '未知消息'
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -19,7 +19,7 @@
|
|||||||
{
|
{
|
||||||
"adapter": "aiocqhttp",
|
"adapter": "aiocqhttp",
|
||||||
"enable": false,
|
"enable": false,
|
||||||
"host": "127.0.0.1",
|
"host": "0.0.0.0",
|
||||||
"port": 8080
|
"port": 8080
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user