Skip to content

Commit 916355b

Browse files
authored
Fixing PR conflicts (#2)
* Fixing PR conflicts * fix relative path
1 parent e4c34d0 commit 916355b

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
phi3v/
2+
quantized_phi3v/
3+
adapters/
4+
*.egg-info
5+
*.json
6+
.DS_STORE
7+
.DS_Store
8+
__pycache__/

examples/main.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
''''
2+
This is a simple example of how to use the Phi-3 Vision MLX agent.
3+
The agent can be used for Visual Question Answering, Generative Feedback Loop, API Tool Use, and more.
4+
5+
Author: Josef Albers
6+
7+
More examples here: https://github.com/JosefAlbers/Phi-3-Vision-MLX
8+
'''
9+
10+
import sys
11+
import os
12+
13+
# Add the parent folder of phi_3_vision_mlx module to the Python module search path
14+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
15+
16+
from phi_3_vision_mlx import Agent
17+
18+
# Visual Question Answering (VQA)
19+
agent = Agent()
20+
agent('What is shown in this image?', 'https://collectionapi.metmuseum.org/api/collection/v1/iiif/344291/725918/main-image')
21+
agent.end()
22+
23+
# Generative Feedback Loop
24+
# The agent can be used to generate code, execute it, and then modify it based on feedback
25+
26+
agent('Plot a Lissajous Curve.')
27+
agent('Modify the code to plot 3:4 frequency')
28+
agent.end()
29+
30+
# API Tool Use
31+
# You can use the agent to create images or generate speech using API calls
32+
33+
agent('Draw "A perfectly red apple, 32k HDR, studio lighting"')
34+
agent.end()
35+
agent('Speak "People say nothing is impossible, but I do nothing every day."')
36+
agent.end()
37+

phi_3_vision_mlx.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,10 @@ def _apply_chat_template(prompt, images, verbose, apply_chat_template=True):
734734
img_prompt = ''
735735
prompt = [prompt] if isinstance(prompt, str) else prompt
736736
prompt = [f"<|user|>\n{img_prompt}{i}<|end|>\n<|assistant|>\n" for i in prompt]
737-
print(f'### Prompt ###\n{"\n".join(map(str.strip, prompt)).strip()}\n### Images ###\n{"\n".join(map(str, images)) if images else "None"}\n### Output ###') if verbose else None
737+
if verbose:
738+
prompt_str = "\n".join(map(str.strip, prompt)).strip()
739+
images_str = "\n".join(map(str, images)) if images else "None"
740+
print(f'### Prompt ###\n{prompt_str}\n### Images ###\n{images_str}\n### Output ###')
738741
prompt = prompt[0] if len(prompt) == 1 else prompt
739742
return prompt, images
740743

0 commit comments

Comments
 (0)