Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yunwei
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
wanghongliang
yunwei
Commits
10d471e2
提交
10d471e2
authored
7月 04, 2024
作者:
martin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ollama调用的封装客户端及调用示例
上级
d8c61815
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
0 行删除
+57
-0
chat_calling.py
tmp/chat_calling.py
+19
-0
chat_cli.py
tmp/chat_cli.py
+38
-0
没有找到文件。
tmp/chat_calling.py
0 → 100644
浏览文件 @
10d471e2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/7/4 09:51
# @Author : Martin
"""
功能描述:
"""
from
chat_cli
import
ChatCli
content
=
'介绍下阿基米德这个人'
# a = ChatCli(model='qwen2', url='http://116.63.135.219:11434/api/generate')
# a.chat(content, stream=True)
b
=
ChatCli
(
url
=
'http://116.63.135.219:11434/api/generate'
)
res
=
b
.
chat
(
content
,
stream
=
True
)
print
(
type
(
res
))
if
res
:
for
i
in
res
:
print
(
i
,
end
=
''
)
tmp/chat_cli.py
0 → 100644
浏览文件 @
10d471e2
import
requests
import
json
class
ChatCli
:
def
__init__
(
self
,
url
=
'http://192.168.1.149:11434/api/generate'
,
model
=
'gemma2'
):
self
.
url
=
url
self
.
model
=
model
def
chat
(
self
,
chat_content
,
stream
=
False
):
data
=
{
"model"
:
self
.
model
,
"prompt"
:
chat_content
,
"stream"
:
stream
}
response
=
requests
.
post
(
self
.
url
,
data
=
json
.
dumps
(
data
),
headers
=
{
'Content-Type'
:
'application/json'
},
stream
=
stream
)
# 检查请求状态码
if
response
.
status_code
==
200
:
print
(
f
"**Reply form {self.model}**"
)
# 请求成功,打印响应内容
if
stream
:
for
line
in
response
.
iter_lines
():
# print(json.loads(line.decode())['response'], end='')
yield
json
.
loads
(
line
.
decode
())[
'response'
]
else
:
res
=
response
.
json
()[
'response'
]
yield
res
else
:
# 请求失败,打印错误信息
print
(
f
"请求失败,状态码:{response.status_code}"
)
yield
''
if
__name__
==
'__main__'
:
a
=
ChatCli
(
url
=
'http://116.63.135.219:11434/api/generate'
,
model
=
'gemma2'
)
cc
=
"""你好"""
a
.
chat
(
cc
,
stream
=
True
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论