Skip to content

Commit 70ac1df

Browse files
authored
Merge pull request browser-use#294 from fyq163/my_dev
Adding Moonshot model and correct image extension
2 parents ade5f53 + d3eeb81 commit 70ac1df

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.env.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ OLLAMA_ENDPOINT=http://localhost:11434
2121
ALIBABA_ENDPOINT=https://dashscope.aliyuncs.com/compatible-mode/v1
2222
ALIBABA_API_KEY=
2323

24+
MOONSHOT_ENDPOINT=https://api.moonshot.cn/v1
25+
MOONSHOT_API_KEY=
26+
2427
# Set to false to disable anonymized telemetry
2528
ANONYMIZED_TELEMETRY=true
2629

@@ -44,4 +47,4 @@ RESOLUTION_WIDTH=1920
4447
RESOLUTION_HEIGHT=1080
4548

4649
# VNC settings
47-
VNC_PASSWORD=youvncpassword
50+
VNC_PASSWORD=youvncpassword

src/utils/utils.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"anthropic": "Anthropic",
2121
"deepseek": "DeepSeek",
2222
"google": "Google",
23-
"alibaba": "Alibaba"
23+
"alibaba": "Alibaba",
24+
"moonshot": "MoonShot"
2425
}
2526

2627
def get_llm_model(provider: str, **kwargs):
@@ -149,6 +150,14 @@ def get_llm_model(provider: str, **kwargs):
149150
base_url=base_url,
150151
api_key=api_key,
151152
)
153+
154+
elif provider == "moonshot":
155+
return ChatOpenAI(
156+
model=kwargs.get("model_name", "moonshot-v1-32k-vision-preview"),
157+
temperature=kwargs.get("temperature", 0.0),
158+
base_url=os.getenv("MOONSHOT_ENDPOINT"),
159+
api_key=os.getenv("MOONSHOT_API_KEY"),
160+
)
152161
else:
153162
raise ValueError(f"Unsupported provider: {provider}")
154163

tests/test_llm_api.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ class LLMConfig:
2222

2323
def create_message_content(text, image_path=None):
2424
content = [{"type": "text", "text": text}]
25-
25+
image_format = "png" if image_path and image_path.endswith(".png") else "jpeg"
2626
if image_path:
2727
from src.utils import utils
2828
image_data = utils.encode_image(image_path)
2929
content.append({
3030
"type": "image_url",
31-
"image_url": {"url": f"data:image/jpeg;base64,{image_data}"}
31+
"image_url": {"url": f"data:image/{image_format};base64,{image_data}"}
3232
})
33-
3433
return content
3534

3635
def get_env_value(key, provider):
@@ -41,6 +40,7 @@ def get_env_value(key, provider):
4140
"deepseek": {"api_key": "DEEPSEEK_API_KEY", "base_url": "DEEPSEEK_ENDPOINT"},
4241
"mistral": {"api_key": "MISTRAL_API_KEY", "base_url": "MISTRAL_ENDPOINT"},
4342
"alibaba": {"api_key": "ALIBABA_API_KEY", "base_url": "ALIBABA_ENDPOINT"},
43+
"moonshot":{"api_key": "MOONSHOT_API_KEY", "base_url": "MOONSHOT_ENDPOINT"},
4444
}
4545

4646
if provider in env_mappings and key in env_mappings[provider]:
@@ -122,6 +122,10 @@ def test_mistral_model():
122122
config = LLMConfig(provider="mistral", model_name="pixtral-large-latest")
123123
test_llm(config, "Describe this image", "assets/examples/test.png")
124124

125+
def test_moonshot_model():
126+
config = LLMConfig(provider="moonshot", model_name="moonshot-v1-32k-vision-preview")
127+
test_llm(config, "Describe this image", "assets/examples/test.png")
128+
125129
if __name__ == "__main__":
126130
# test_openai_model()
127131
# test_google_model()

0 commit comments

Comments
 (0)