embedding.py 579 B

12345678910111213141516171819202122232425
  1. from openai import OpenAI
  2. # Modify OpenAI's API key and API base to use Aphrodite's API server.
  3. openai_api_key = "EMPTY"
  4. openai_api_base = "http://localhost:2242/v1"
  5. client = OpenAI(
  6. # defaults to os.environ.get("OPENAI_API_KEY")
  7. api_key=openai_api_key,
  8. base_url=openai_api_base,
  9. )
  10. models = client.models.list()
  11. model = models.data[0].id
  12. responses = client.embeddings.create(
  13. input=[
  14. "Hello my name is",
  15. "The weather is nice today",
  16. ],
  17. model=model,
  18. )
  19. for data in responses.data:
  20. print(data.embedding) # list of float of len 4096