Skip to content

Commit

Permalink
Add support for Azure OpenAI, Palm, Replicate, Sagemaker (100+LLMs) -…
Browse files Browse the repository at this point in the history
… using litellm (IDEA-Research#369)

* v0 litellm

* v0 litellm
  • Loading branch information
ishaan-jaff authored Sep 6, 2023
1 parent f34e1a3 commit 220f49b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions automatic_label_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import torchvision
from PIL import Image, ImageDraw, ImageFont
import nltk
import litellm

# Grounding DINO
import GroundingDINO.groundingdino.datasets.transforms as T
Expand Down Expand Up @@ -66,7 +67,7 @@ def generate_tags(caption, split=',', max_tokens=100, model="gpt-3.5-turbo"):
f'Caption: {caption}.'
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "noun: xxx, xxx, xxx"
tags = reply.split(':')[-1].strip()
Expand Down Expand Up @@ -96,7 +97,7 @@ def check_caption(caption, pred_phrases, max_tokens=100, model="gpt-3.5-turbo"):
'Only give the revised caption: '
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "Caption: xxx, xxx, xxx"
caption = reply.split(':')[-1].strip()
Expand Down
3 changes: 2 additions & 1 deletion automatic_label_ram_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import torch
import torchvision
from PIL import Image
import litellm

# Grounding DINO
import GroundingDINO.groundingdino.datasets.transforms as T
Expand Down Expand Up @@ -67,7 +68,7 @@ def check_tags_chinese(tags_chinese, pred_phrases, max_tokens=100, model="gpt-3.
'Only give the revised tags_chinese: '
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "tags_chinese: xxx, xxx, xxx"
tags_chinese = reply.split(':')[-1].strip()
Expand Down
5 changes: 3 additions & 2 deletions automatic_label_tag2text_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import torch
import torchvision
from PIL import Image, ImageDraw, ImageFont
import litellm

# Grounding DINO
import GroundingDINO.groundingdino.datasets.transforms as T
Expand Down Expand Up @@ -69,7 +70,7 @@ def generate_tags(caption, split=',', max_tokens=100, model="gpt-3.5-turbo"):
f'Caption: {caption}.'
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "noun: xxx, xxx, xxx"
tags = reply.split(':')[-1].strip()
Expand Down Expand Up @@ -99,7 +100,7 @@ def check_caption(caption, pred_phrases, max_tokens=100, model="gpt-3.5-turbo"):
'Only give the revised caption: '
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "Caption: xxx, xxx, xxx"
caption = reply.split(':')[-1].strip()
Expand Down
3 changes: 2 additions & 1 deletion gradio_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import gradio as gr
import argparse
import litellm

import numpy as np
import torch
Expand Down Expand Up @@ -73,7 +74,7 @@ def generate_tags(caption, split=',', max_tokens=100, model="gpt-3.5-turbo", ope
f'Caption: {caption}.'
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
# sometimes return with "noun: xxx, xxx, xxx"
tags = reply.split(':')[-1].strip()
Expand Down
3 changes: 2 additions & 1 deletion grounded_sam_whisper_inpainting_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import torch
from PIL import Image, ImageDraw, ImageFont
import litellm

# Grounding DINO
import GroundingDINO.groundingdino.datasets.transforms as T
Expand Down Expand Up @@ -144,7 +145,7 @@ def filter_prompts_with_chatgpt(caption, max_tokens=100, model="gpt-3.5-turbo"):
f'Given caption: {caption}.'
}
]
response = openai.ChatCompletion.create(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
response = litellm.completion(model=model, messages=prompt, temperature=0.6, max_tokens=max_tokens)
reply = response['choices'][0]['message']['content']
try:
det_prompt, inpaint_prompt = reply.split('\n')[0].split(':')[-1].strip(), reply.split('\n')[1].split(':')[-1].strip()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ transformers
yapf
nltk
fairscale
litellm

0 comments on commit 220f49b

Please sign in to comment.