|
| 1 | +import os |
| 2 | +from ollama import Client |
| 3 | + |
| 4 | +OLLAMA_HOST = os.getenv('OLLAMA_HOST') |
| 5 | +ollama_client = Client(host=OLLAMA_HOST) |
| 6 | + |
| 7 | +instructions = """You are an expert of the StarTrek universe. |
| 8 | +Make only short answers. Speak like a Vulcan |
| 9 | +""" |
| 10 | + |
| 11 | +context=""" |
| 12 | +James Tiberius Kirk is a fictional character in the Star Trek media franchise. |
| 13 | +Kirk was first played by William Shatner as the captain of the USS Enterprise in the Star Trek: The Original Series. |
| 14 | +
|
| 15 | +The best friends of James T. Kirk are: |
| 16 | +- Spock: The Vulcan science officer of the USS Enterprise. |
| 17 | +- Leonard McCoy: The ship's chief medical officer. |
| 18 | +
|
| 19 | +Here are some of main adversaries/enemies of James T. Kirk: |
| 20 | +- Klingons: The warrior race was often at odds with the Federation and Kirk personally. |
| 21 | +- Khan Noonien Singh: A genetically engineered superhuman and Kirk's most famous nemesis. |
| 22 | +- Romulans: Another major alien race often in conflict with the Federation. |
| 23 | +""" |
| 24 | + |
| 25 | +while True: |
| 26 | + user_input = input("π€ (type 'bye' to exit):> ") |
| 27 | + if user_input.lower() == "bye": |
| 28 | + print("π Goodbye!") |
| 29 | + break |
| 30 | + else: |
| 31 | + stream = ollama_client.chat( |
| 32 | + model='granite3-moe:1b', |
| 33 | + messages=[ |
| 34 | + {'role': 'system', 'content': instructions}, |
| 35 | + {'role': 'system', 'content': context}, |
| 36 | + {'role': 'user', 'content': user_input}, |
| 37 | + ], |
| 38 | + options={"temperature":0.5}, |
| 39 | + stream=True, |
| 40 | + ) |
| 41 | + |
| 42 | + for chunk in stream: |
| 43 | + print(chunk['message']['content'], end='', flush=True) |
| 44 | + |
| 45 | + print("\n") |
0 commit comments