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

feat(LLM/providers): Adding oLlama as LLM Provider #968

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonymusky
Copy link

@jonymusky jonymusky commented Dec 12, 2024

This pull request introduces several significant changes to support multiple LLM providers, specifically OpenAI and Ollama, and enhances the error handling and schema normalization processes. The most important changes include the addition of new environment variables, updating function names and imports to be more generic, and implementing specific embedding and completion functions for Ollama.

Support for multiple LLM providers:

  • apps/api/.env.example: Added new environment variables LLM_PROVIDER, OLLAMA_URL, MODEL_NAME, and OLLAMA_EMBEDDING_MODEL to configure the LLM provider and model.
  • apps/api/src/lib/ranker.ts: Introduced the LLMProvider type and functions getOpenAIEmbedding and getOllamaEmbedding to handle embeddings for different LLM providers. Updated getEmbedding to switch between providers based on the environment variable. [1] [2]

Refactoring and renaming for LLM provider generalization:

Enhanced error handling and schema normalization:

These changes collectively enhance the flexibility of the application to support multiple LLM providers and improve the robustness of the embedding and completion processes.

Example using Ollama:
Screenshot 2024-12-11 at 10 57 21 PM

curl -X POST http://localhost:3002/v1/scrape \
    -H 'Content-Type: application/json' \
    -d '{
      "url": "https://auto.mercadolibre.com.ar/MLA-1459615671-gwm-haval-h6-4wd-gt-_JM",
      "formats": ["extract"],
      "extract": {
        "schema": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "The URL of the product"
            },
            "name": {
              "type": "string",
              "description": "The product name/title"
            },
            "price": {
              "type": "number",
              "description": "The current price of the product"
            },
            "currency": {
              "type": "string",
              "description": "Currency code (USD, EUR, etc)"
            },
            "main_image_url": {
              "type": "string",
              "description": "The URL of the main image of the product"
            }
          },
          "required": ["url", "name", "price", "currency", "main_image_url"]
        }
      }
    }'

Output:

{"success":true,"data":{"metadata":{"title":"Gwm Haval H6 4wd Gt | MercadoLibre","description":"Gwm Haval H6 4wd Gt","language":"es-AR","ogTitle":"Gwm Haval H6 4wd Gt - $ 56.500.000","ogDescription":"RYOKU MOTORS, Concesionario.Para recibir asesoramiento detallado, hacé click en el botón de Whatsapp.» Documentación rápida.» Tomamos el dolar al mejor valor.","ogUrl":"https://auto.mercadolibre.com.ar/MLA-1459615671-gwm-haval-h6-4wd-gt-_JM","ogImage":"https://http2.mlstatic.com/D_NQ_NP_671104-MLA80280958464_112024-O.jpg","ogLocaleAlternate":[],"viewport":"width=device-width, initial-scale=1.0, maximum-scale=5.0","HandheldFriendly":"True","browser-support":"samesite=true","csrf-token":["cSVvuJKw-bZJGOFSlC8hToDWsRx6T-FJpr0A","cSVvuJKw-bZJGOFSlC8hToDWsRx6T-FJpr0A"],"twitter:card":"product","twitter:site":"Mercado Libre","twitter:title":"Gwm Haval H6 4wd Gt","twitter:description":"RYOKU MOTORS, Concesionario.Para recibir asesoramiento detallado, hacé click en el botón de Whatsapp.» Documentación rápida.» Tomamos el dolar al mejor valor.","twitter:image":"https://http2.mlstatic.com/D_NQ_NP_671104-MLA80280958464_112024-O.jpg","twitter:domain":"mercadolibre.com.ar","twitter:app:name:iphone":"Mercado Libre","twitter:app:id:iphone":"463624852","twitter:app:url:iphone":"meli://item?id=MLA1459615671","twitter:app:name:ipad":"Mercado Libre","twitter:app:id:ipad":"463624852","twitter:app:url:ipad":"meli://item?id=MLA1459615671","twitter:app:name:googleplay":"Mercado Libre","twitter:app:id:googleplay":"com.mercadolibre","twitter:app:url:googleplay":"meli://item?id=MLA1459615671","og:description":"RYOKU MOTORS, Concesionario.Para recibir asesoramiento detallado, hacé click en el botón de Whatsapp.» Documentación rápida.» Tomamos el dolar al mejor valor.","og:image":"https://http2.mlstatic.com/D_NQ_NP_671104-MLA80280958464_112024-O.jpg","og:title":"Gwm Haval H6 4wd Gt - $ 56.500.000","og:type":"meli-ar:product","og:url":"https://auto.mercadolibre.com.ar/MLA-1459615671-gwm-haval-h6-4wd-gt-_JM","fb:app_id":"175268255910551","al:android:url":"meli://item?id=MLA1459615671","al:android:app_name":"Mercado Libre","al:android:package":"com.mercadolibre","al:iphone:url":"meli://item?id=MLA1459615671","al:iphone:app_name":"Mercado Libre","al:iphone:app_store_id":"463624852","sourceURL":"https://auto.mercadolibre.com.ar/MLA-1459615671-gwm-haval-h6-4wd-gt-_JM","url":"https://auto.mercadolibre.com.ar/MLA-1459615671-gwm-haval-h6-4wd-gt-_JM","statusCode":200},"extract":{"role":"assistant","content":"{\"currency\":\"USD\",\"main_image_url\":\"\",\"name\":\"American Express Centurion Card\",\"price\":0,\"url\":\"https://www.americanexpress.com/credit-cards/centurion-card/overview/\"}"}}}

Screenshot 2024-12-11 at 11 01 24 PM

Warning ⚠️

I just confirmed that Ollama is functioning correctly on my local setup.

@jonymusky jonymusky changed the title feat(LLM/providers): Adding oLlama to use it locally without paying OpenAI feat(LLM/providers): Adding oLlama as LLM Provider Dec 12, 2024
@ericciarla
Copy link
Contributor

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants