MCPcopy Create free account
hub / github.com/AmberSahdev/Open-Interface / LLM

Class LLM

app/llm.py:12–91  ·  view source on GitHub ↗

LLM Request { "original_user_request": ..., "step_num": ..., "screenshot": ... } step_num is the count of times we've interacted with the LLM for this user request. If it's 0, we know it's a fresh user request. If it's greater than 0, then we know we are

Source from the content-addressed store, hash-verified

10
11
12class LLM:
13 """
14 LLM Request
15 {
16 "original_user_request": ...,
17 "step_num": ...,
18 "screenshot": ...
19 }
20
21 step_num is the count of times we've interacted with the LLM for this user request.
22 If it's 0, we know it's a fresh user request.
23 If it's greater than 0, then we know we are already in the middle of a request.
24 Therefore, if the number is positive and from the screenshot it looks like request is complete, then return an
25 empty list in steps and a string in done. Don't keep looping the same request.
26
27 Expected LLM Response
28 {
29 "steps": [
30 {
31 "function": "...",
32 "parameters": {
33 "key1": "value1",
34 ...
35 },
36 "human_readable_justification": "..."
37 },
38 {...},
39 ...
40 ],
41 "done": ...
42 }
43
44 function is the function name to call in the executer.
45 parameters are the parameters of the above function.
46 human_readable_justification is what we can use to debug in case program fails somewhere or to explain to user why we're doing what we're doing.
47 done is null if user request is not complete, and it's a string when it's complete that either contains the
48 information that the user asked for, or just acknowledges completion of the user requested task. This is going
49 to be communicated to the user if it's present.
50 """
51
52 def __init__(self):
53 self.settings_dict: dict[str, str] = Settings().get_dict()
54 model_name, base_url, api_key = self.get_settings_values()
55
56 self.model_name = model_name
57 context = self.read_context_txt_file()
58
59 self.model = ModelFactory.create_model(self.model_name, base_url, api_key, context)
60
61 def get_settings_values(self) -> tuple[str, str, str]:
62 model_name = self.settings_dict.get('model') or DEFAULT_MODEL_NAME
63 base_url = (self.settings_dict.get('base_url') or 'https://api.openai.com/v1/').rstrip('/') + '/'
64 api_key = self.settings_dict.get('api_key')
65
66 return model_name, base_url, api_key
67
68 def read_context_txt_file(self) -> str:
69 # Construct context for the assistant by reading context.txt and adding extra system information

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected