Skip to content

Instantly share code, notes, and snippets.

@grantjenks
Created January 21, 2023 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantjenks/1020ba22f2f56a9d2279cf98f304e525 to your computer and use it in GitHub Desktop.
Save grantjenks/1020ba22f2f56a9d2279cf98f304e525 to your computer and use it in GitHub Desktop.
Proof of Concept for "On-call Assistant"
$ ipython
Python 3.8.4 (v3.8.4:dfa645a65e, Jul 13 2020, 10:45:06)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from langchain.agents import Tool, initialize_agent
...: from langchain.agents import load_tools
...: from langchain.llms import OpenAI
...:
In [2]: def get_service_name(service_description):
...: service_map = {'django rrweb': 'django-rrweb'}
...: return service_map.get(service_description, 'unknown')
...:
In [3]: def ps_report(service_name):
...: assert service_name != 'unknown'
...: output = !ssh dokku@iron ps:report $service_name
...: return '\n'.join(output)
...:
In [4]: tools = [
...: Tool(
...: name='get service name',
...: func=get_service_name,
...: description=(
...: 'useful for retrieving a service name'
...: ' given a description of the service'
...: ),
...: ),
...: Tool(
...: name='ps report for service',
...: func=ps_report,
...: description=(
...: 'useful for a summary of running service information.'
...: ' the input to this tool should be a service name'
...: ),
...: ),
...: ]
...:
In [5]: llm = OpenAI(temperature=0)
...:
In [6]: agent = initialize_agent(
...: tools,
...: llm,
...: agent='zero-shot-react-description',
...: verbose=True,
...: )
...:
In [7]: agent.run('How many processes is django rrweb currently running?')
...:
> Entering new AgentExecutor chain...
I need to find the service name for django rrweb
Action: get service name
Action Input: django rrweb
Observation: django-rrweb
Thought: I need to get a report of the running processes for django-rrweb
Action: ps report for service
Action Input: django-rrweb
Observation: =====> django-rrweb ps information
Deployed: true
Processes: 2
Ps can scale: true
Ps computed procfile path: Procfile
Ps global procfile path: Procfile
Ps procfile path:
Ps restart policy: on-failure:10
Restore: true
Running: true
Status rrwebpurge 1: running (CID: 7c71e8094ce)
Status web 1: running (CID: bd40fd7645e)
Thought: I now know the final answer
Final Answer: django-rrweb is currently running 2 processes.
> Finished chain.
Out[7]: 'django-rrweb is currently running 2 processes.'
In [8]: agent.run(
...: 'What is the container id of the rrweb purge process'
...: ' running in the django rrweb service?'
...: )
...:
> Entering new AgentExecutor chain...
I need to find the service name first.
Action: get service name
Action Input: django rrweb
Observation: django-rrweb
Thought: Now I need to get the running service information.
Action: ps report for service
Action Input: django-rrweb
Observation: =====> django-rrweb ps information
Deployed: true
Processes: 2
Ps can scale: true
Ps computed procfile path: Procfile
Ps global procfile path: Procfile
Ps procfile path:
Ps restart policy: on-failure:10
Restore: true
Running: true
Status rrwebpurge 1: running (CID: 7c71e8094ce)
Status web 1: running (CID: bd40fd7645e)
Thought: I now know the container id of the rrweb purge process.
Final Answer: 7c71e8094ce
> Finished chain.
Out[8]: '7c71e8094ce'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment