Skip to content

Commit

Permalink
add jsonschema as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
JianxinMa committed Sep 3, 2024
1 parent 653a702 commit 3184504
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/llm_vl_mix_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test():
'role':
'user',
'content': [{
'text': '框出太阳并描述'
'text': '框出小狗并描述',
}, {
'image': 'https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg'
'image': 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg',
}]
}]
response = llm_vl.chat(messages, stream=True)
Expand Down
4 changes: 2 additions & 2 deletions examples/multi_agent_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def init_agent_service():

def test(
query: str = 'hello',
image: str = 'https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg',
image: str = 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg',
file: Optional[str] = os.path.join(ROOT_RESOURCE, 'poem.pdf'),
):
# Define the agent
Expand Down Expand Up @@ -66,7 +66,7 @@ def app_tui():
messages = []
while True:
query = input('user question: ')
# Image example: https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg
# Image example: https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg
image = input('image url (press enter if no image): ')
# File example: resource/poem.pdf
file = input('file url (press enter if no file): ').strip()
Expand Down
4 changes: 2 additions & 2 deletions examples/visual_storytelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _run(self, messages: List[Message], lang: str = 'zh', **kwargs) -> Iterator[


def test(query: Optional[str] = '看图说话',
image: str = 'https://img01.sc115.com/uploads3/sc/vector/201809/51413-20180914205509.jpg'):
image: str = 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'):
# define a writer agent
bot = VisualStorytelling(llm={'model': 'qwen-max'})

Expand All @@ -71,7 +71,7 @@ def app_tui():
messages = []
while True:
query = input('user question: ')
# image example: https://img01.sc115.com/uploads3/sc/vector/201809/51413-20180914205509.jpg
# image example: https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg
image = input('image url: ').strip()

if not image:
Expand Down
2 changes: 1 addition & 1 deletion qwen_agent/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, cfg: Optional[Dict] = None):
self.generate_cfg = generate_cfg

def quick_chat(self, prompt: str) -> str:
responses = self.chat(messages=[Message(role=USER, content=prompt)], stream=False)
*_, responses = self.chat(messages=[Message(role=USER, content=prompt)])
assert len(responses) == 1
assert not responses[0].function_call
assert isinstance(responses[0].content, str)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def read_description() -> str:
'eval_type_backport',
'json5',
'jsonlines',
'jsonschema',
'openai',
'pydantic>=2.3.0',
'requests',
Expand Down
11 changes: 4 additions & 7 deletions tests/agents/test_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,10 @@ def test_assistant_vl():
agent = Assistant(llm=llm_cfg)

messages = [
Message(
'user',
[
ContentItem(text='用一句话描述图片'),
ContentItem(image= # NOQA
'https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg')
])
Message('user', [
ContentItem(text='用一句话描述图片'),
ContentItem(image='https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'),
])
]

*_, last = agent.run(messages)
Expand Down
2 changes: 1 addition & 1 deletion tests/agents/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_router():
messages = [
Message('user', [
ContentItem(text='描述图片'),
ContentItem(image='https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg'),
ContentItem(image='https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'),
])
]

Expand Down
4 changes: 2 additions & 2 deletions tests/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_llm_vl_mix_text():


@pytest.mark.parametrize('query', [None, '看图说话'])
@pytest.mark.parametrize('image', ['https://img01.sc115.com/uploads3/sc/vector/201809/51413-20180914205509.jpg'])
@pytest.mark.parametrize('image', ['https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'])
def test_visual_storytelling(query, image):
visual_storytelling(query=query, image=image)

Expand Down Expand Up @@ -69,7 +69,7 @@ def test_llm_riddles():


@pytest.mark.parametrize('query', ['告诉我你现在知道什么了'])
@pytest.mark.parametrize('image', [None, 'https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg'])
@pytest.mark.parametrize('image', [None, 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'])
@pytest.mark.parametrize('file', [None, os.path.join(ROOT_RESOURCE, 'poem.pdf')])
def test_multi_agent_router(query, image, file):
multi_agent_router(query=query, image=image, file=file)
Expand Down
5 changes: 3 additions & 2 deletions tests/llm/test_dashscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def test_vl_mix_text(functions, stream, delta_stream):
# Chat with vl llm
llm_vl = get_chat_model(llm_cfg_vl)
messages = [{
'role': 'user',
'role':
'user',
'content': [{
'text': '框出太阳'
}, {
'image': 'https://img01.sc115.com/uploads/sc/jpgs/1505/apic11540_sc115.com.jpg'
'image': 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg'
}]
}]
response = llm_vl.chat(messages=messages, functions=None, stream=stream, delta_stream=delta_stream)
Expand Down

0 comments on commit 3184504

Please sign in to comment.