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

[Bug]: How to use the embedding model of ollama #2588

Closed
wwjCMP opened this issue May 13, 2024 · 2 comments
Closed

[Bug]: How to use the embedding model of ollama #2588

wwjCMP opened this issue May 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@wwjCMP
Copy link

wwjCMP commented May 13, 2024

What happened?

def get_embeddings():
settings = BrainSettings() # pyright: ignore reportPrivateUsage=none
if settings.ollama_api_base_url:
embeddings = OllamaEmbeddings(
model="ollama/nomic-embed-text:latest"
) # pyright: ignore reportPrivateUsage=none
else:
embeddings = OpenAIEmbeddings() # pyright: ignore reportPrivateUsage=none
return embeddings

I have set it as above, but the following error occurred:

Relevant log output

2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
2024-05-14 00:02:24     result = await app(  # type: ignore[func-returns-value]
2024-05-14 00:02:24              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
2024-05-14 00:02:24     return await self.app(scope, receive, send)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
2024-05-14 00:02:24     await super().__call__(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
2024-05-14 00:02:24     await self.middleware_stack(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
2024-05-14 00:02:24     await self.app(scope, receive, _send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 93, in __call__
2024-05-14 00:02:24     await self.simple_response(scope, receive, send, request_headers=headers)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 148, in simple_response
2024-05-14 00:02:24     await self.app(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
2024-05-14 00:02:24     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-05-14 00:02:24     await app(scope, receive, sender)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
2024-05-14 00:02:24     await self.middleware_stack(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
2024-05-14 00:02:24     await route.handle(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
2024-05-14 00:02:24     await self.app(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
2024-05-14 00:02:24     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-05-14 00:02:24     await app(scope, receive, sender)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
2024-05-14 00:02:24     response = await func(request)
2024-05-14 00:02:24                ^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
2024-05-14 00:02:24     raw_response = await run_endpoint_function(
2024-05-14 00:02:24                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
2024-05-14 00:02:24     return await dependant.call(**values)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/controller/brain_routes.py", line 103, in create_new_brain
2024-05-14 00:02:24     new_brain = brain_service.create_brain(
2024-05-14 00:02:24                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/service/brain_service.py", line 142, in create_brain
2024-05-14 00:02:24     return self.create_brain_integration(user_id, brain)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/service/brain_service.py", line 192, in create_brain_integration
2024-05-14 00:02:24     created_brain = self.brain_repository.create_brain(brain)
2024-05-14 00:02:24                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/repository/brains.py", line 22, in create_brain
2024-05-14 00:02:24     embeddings = get_embeddings()
2024-05-14 00:02:24                  ^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/models/settings.py", line 164, in get_embeddings
2024-05-14 00:02:24     )  # pyright: ignore reportPrivateUsage=none
2024-05-14 00:02:24               ^^^^
2024-05-14 00:02:24 NameError: name 'self' is not defined

Twitter / LinkedIn details

No response

@wwjCMP wwjCMP added the bug Something isn't working label May 13, 2024
Copy link

dosubot bot commented May 13, 2024

The error NameError: name 'self' is not defined suggests there's a problem with how self is used in your code. In Python, self is used within class methods to refer to the instance of the class. If you're seeing this error, it likely means self is being used outside of a class method or in a context where it's not defined.

From the code snippet you shared, self is not explicitly used, which indicates the issue might be in another part of your code not shown here. It's important to ensure that self is only used within class instance methods.

Additionally, the instantiation of OllamaEmbeddings in your code does not show a misuse of self, but make sure the parameters you're passing (like model="ollama/nomic-embed-text:latest") match the expected parameters of the OllamaEmbeddings class. Specifically, if OllamaEmbeddings expects a base_url parameter, ensure you're providing it correctly.

If the problem persists, please provide more context or the specific part of the code where self is used, along with any additional error messages or tracebacks. This will help in diagnosing the issue more accurately.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@wwjCMP
Copy link
Author

wwjCMP commented May 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant