Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing openai llm and functions by using ollama llms #29519

Open
5 tasks done
bhanu1106 opened this issue Jan 31, 2025 · 0 comments
Open
5 tasks done

replacing openai llm and functions by using ollama llms #29519

bhanu1106 opened this issue Jan 31, 2025 · 0 comments
Labels
Ɑ: models Related to LLMs or chat model modules

Comments

@bhanu1106
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

Hi , I am using langchain setup , I need to replace openi ai api keys with ollama llms and also llm.bind_tools(tools) functionality using ollama functions if needed.

def initialize_agent(entity_id: str, user_email: str, memory: ConversationBufferMemory):

llm = ChatOpenAI(
    model="gpt-4-turbo",
    temperature=0,
openai_api_key=OPENAI_API_KEY
)

ticket_system = TicketSystem(entity_id, user_email)


tools = [
   StructuredTool.from_function(
        name="create_ticket",
        func=ticket_system.create_ticket, 
        description="""Create a new ticket after collecting all required information.
        
        Required parameters (must be collected through conversation):
        - title: Title of the ticket
        - message: Detailed description of the issue/request
        - category: Ticket category
        - category_id: Category identifier
        - requestor_name: Name of the requester
        - requested_by: Email of the requester
        - assigned_to: Email of the assignee
        - assignee_name: Name of the assignee
        - status: Initial status of the ticket (e.g., 'Assigned')
        - assigned_by: Email of the assigner
        - assigner_name: Name of the assigner
        - action: Initial action of the ticket (e.g., 'Opened')
        - sub_category: Sub-category of the ticket
        - sub_category_id: Sub-category identifier""",
    ),
    Tool(
        name="get_assigned_tickets",
        func=ticket_system._get_assigned_tickets,
        description="Use this tool to get  information about assigned tasks. Optional params: page (default=1), limit (default=10), status."
    ),
    Tool(
        name="get_requested_tickets",
        func=ticket_system._get_requested_tickets,
        description="Use this tool to get information about requested. Optional params: page (default=1), limit (default=10), status."
    ),
    Tool(
        name="get_ticket_details",
        func=ticket_system._get_ticket_details,
        description="Use this tool to view detailed information about specific ticket id. Optional params: ticket_id"
    )
]

prompt = ChatPromptTemplate.from_messages([
    ("system", SYSTEM_PROMPT),
    MessagesPlaceholder(variable_name="chat_history"),
    ("user", "{input}"),
    MessagesPlaceholder(variable_name="agent_scratchpad"),
])

llm_with_tools = llm.bind_tools(tools)

agent = (
    {
        "input": lambda x: x["input"],
        "agent_scratchpad": lambda x: format_to_openai_tool_messages(x["intermediate_steps"]),
        "chat_history": lambda x: memory.load_memory_variables({})["chat_history"],
    }
    | prompt
    | llm_with_tools
    | OpenAIToolsAgentOutputParser()
) 

return AgentExecutor(
    agent=agent,
    tools=tools,
    verbose=False,
    memory=memory
)

Error Message and Stack Trace (if applicable)

No response

Description

Hi , I am using langchain setup , I need to replace openi ai api keys with ollama llms and also llm.bind_tools(tools) functionality using ollama functions if needed.

System Info

System Information

OS: Linux
OS Version: #23~22.04.1-Ubuntu SMP Thu Jan 16 02:17:57 UTC 2025
Python Version: 3.11.7 (main, Dec 15 2023, 18:12:31) [GCC 11.2.0]

Package Information

langchain_core: 0.3.33
langchain: 0.3.9
langchain_community: 0.3.5
langsmith: 0.1.139
langchain_chroma: 0.1.4
langchain_experimental: 0.3.3
langchain_ollama: 0.2.3
langchain_openai: 0.3.3
langchain_text_splitters: 0.3.2

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.10.10
async-timeout: Installed. No version info available.
chromadb: 0.5.17
dataclasses-json: 0.6.7
fastapi: 0.115.4
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
numpy: 1.26.4
ollama: 0.4.7
openai: 1.58.1
orjson: 3.10.11
packaging: 24.2
pydantic: 2.9.2
pydantic-settings: 2.6.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.35
tenacity: 8.5.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

@dosubot dosubot bot added the Ɑ: models Related to LLMs or chat model modules label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests

1 participant