openai/gpt-oss

Public

mirrored fromhttps://github.com/openai/gpt-ossAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

gpt-oss-mcp-server/reference-system-prompt.py

53lines · modecode

1import datetime
2import os
3
4from gpt_oss.tools.simple_browser import SimpleBrowserTool
5from gpt_oss.tools.simple_browser.backend import ExaBackend, YouComBackend
6from gpt_oss.tools.python_docker.docker_tool import PythonTool
7from gpt_oss.tokenizer import tokenizer
8
9from openai_harmony import (
10 Conversation,
11 DeveloperContent,
12 HarmonyEncodingName,
13 Message,
14 ReasoningEffort,
15 Role,
16 SystemContent,
17 load_harmony_encoding,
18)
19
20encoding = load_harmony_encoding(HarmonyEncodingName.HARMONY_GPT_OSS)
21
22system_message_content = (SystemContent.new().with_reasoning_effort(
23 ReasoningEffort.LOW).with_conversation_start_date(
24 datetime.datetime.now().strftime("%Y-%m-%d")))
25
26tool_backend = os.getenv("BROWSER_BACKEND", "youcom")
27if tool_backend == "youcom":
28 backend = YouComBackend(source="web")
29elif tool_backend == "exa":
30 backend = ExaBackend(source="web")
31else:
32 raise ValueError(f"Invalid tool backend: {tool_backend}")
33browser_tool = SimpleBrowserTool(backend=backend)
34system_message_content = system_message_content.with_tools(
35 browser_tool.tool_config)
36
37python_tool = PythonTool()
38system_message_content = system_message_content.with_tools(
39 python_tool.tool_config)
40
41system_message = Message.from_role_and_content(Role.SYSTEM,
42 system_message_content)
43
44developer_message_content = DeveloperContent.new().with_instructions("")
45developer_message = Message.from_role_and_content(Role.DEVELOPER,
46 developer_message_content)
47
48messages = [system_message, developer_message]
49
50conversation = Conversation.from_messages(messages)
51tokens = encoding.render_conversation(conversation)
52system_message = tokenizer.decode(tokens)
53print(system_message)
54