(
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
)
| 61 | |
| 62 | |
| 63 | def 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) |
nothing calls this directly
no test coverage detected