mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
9.9 KiB
9.9 KiB
In [ ]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[api,pipeline-llm]
# Install OpenCode if not already installed and run serve
!curl -fsSL https://opencode.ai/install | bash
!opencode serve &In [6]:
from IPython.display import Markdown, display
from txtai import LLM
def generate(request):
display(Markdown(llm(request)))
# Connect to OpenCode server and use default LLM provider
llm = LLM("opencode")
generate("Show a Python Hello World example")<IPython.core.display.Markdown object>
In [8]:
generate("Show a simple and basic TxtAI RAG example")<IPython.core.display.Markdown object>
In [9]:
generate("Show a x86 assembly hello world")<IPython.core.display.Markdown object>
In [11]:
generate("""
Fix the following error in the code below and explain what's wrong.
Error:
AttributeError: 'NoneType' object has no attribute 'startswith'
Code:
a = None
a.startswith("hello")
""")<IPython.core.display.Markdown object>
In [16]:
from IPython.display import Markdown, display
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="api-key",
)
response = client.chat.completions.create(
messages=[{
"role": "user",
"content": "Show a Python factorial function",
}],
model="opencode",
)
display(Markdown((response.choices[0].message.content)))<IPython.core.display.Markdown object>