MCPcopy
hub / github.com/zai-org/ChatGLM3 / main

Function main

composite_demo/demo_tool.py:63–208  ·  view source on GitHub ↗
(
        prompt_text: str,
        top_p: float = 0.2,
        temperature: float = 0.1,
        repetition_penalty: float = 1.1,
        max_new_tokens: int = 1024,
        truncate_length: int = 1024,
        retry: bool = False
)

Source from the content-addressed store, hash-verified

61
62
63def main(
64 prompt_text: str,
65 top_p: float = 0.2,
66 temperature: float = 0.1,
67 repetition_penalty: float = 1.1,
68 max_new_tokens: int = 1024,
69 truncate_length: int = 1024,
70 retry: bool = False
71):
72 manual_mode = st.toggle('Manual mode',
73 help='Define your tools in YAML format. You need to supply tool call results manually.'
74 )
75
76 if manual_mode:
77 with st.expander('Tools'):
78 tools = st.text_area(
79 'Define your tools in YAML format here:',
80 yaml.safe_dump([EXAMPLE_TOOL], sort_keys=False),
81 height=400,
82 )
83 tools = yaml_to_dict(tools)
84
85 if not tools:
86 st.error('YAML format error in tools definition')
87 else:
88 tools = get_tools()
89
90 if 'tool_history' not in st.session_state:
91 st.session_state.tool_history = []
92 if 'calling_tool' not in st.session_state:
93 st.session_state.calling_tool = False
94
95 if 'chat_history' not in st.session_state:
96 st.session_state.chat_history = []
97
98 if prompt_text == "" and retry == False:
99 print("\n== Clean ==\n")
100 st.session_state.chat_history = []
101 return
102
103 history: list[Conversation] = st.session_state.chat_history
104 for conversation in history:
105 conversation.show()
106
107 if retry:
108 print("\n== Retry ==\n")
109 last_user_conversation_idx = None
110 for idx, conversation in enumerate(history):
111 if conversation.role == Role.USER:
112 last_user_conversation_idx = idx
113 if last_user_conversation_idx is not None:
114 prompt_text = history[last_user_conversation_idx].content
115 del history[last_user_conversation_idx:]
116
117 if prompt_text:
118 prompt_text = prompt_text.strip()
119 role = st.session_state.calling_tool and Role.OBSERVATION or Role.USER
120 append_conversation(Conversation(role, prompt_text), history)

Callers

nothing calls this directly

Calls 9

get_toolsFunction · 0.90
ConversationClass · 0.90
postprocess_textFunction · 0.90
dispatch_toolFunction · 0.90
yaml_to_dictFunction · 0.85
showMethod · 0.80
append_conversationFunction · 0.70
extract_codeFunction · 0.70
generate_streamMethod · 0.45

Tested by

no test coverage detected