Skip to content

Commit

Permalink
update claude
Browse files Browse the repository at this point in the history
  • Loading branch information
surcyf123 committed Jan 9, 2024
1 parent 3fb62b0 commit 28de990
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions miner/claude_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
valid_hotkeys = []



class StreamMiner(ABC):
def __init__(self, config=None, axon=None, wallet=None, subtensor=None):
bt.logging.info("starting stream miner")
Expand Down Expand Up @@ -390,14 +389,19 @@ async def images(self, synapse: ImageResponse) -> ImageResponse:
model = synapse.model
messages = synapse.messages
size = synapse.size
width, height = self.size.split('x')
width = int(width)
height = int(height)
width = synapse.width
height = synapse.height
quality = synapse.quality
style = synapse.style
seed = synapse.seed
steps = synapse.steps
image_revised_prompt = None
cfg_scale = synapse.cfg_scale
sampler = synapse.sampler
samples = synapse.samples
image_data = {}

bt.logging.debug(f"data = {provider, model, messages, size, width, height, quality, style, seed, steps, image_revised_prompt, cfg_scale, sampler, samples}")

if provider == "OpenAI":
meta = await client.images.generate(
Expand All @@ -409,44 +413,36 @@ async def images(self, synapse: ImageResponse) -> ImageResponse:
)
image_url = meta.data[0].url
image_revised_prompt = meta.data[0].revised_prompt
image_data["url"] = image_url
image_data["image_revised_prompt"] = image_revised_prompt
bt.logging.info(f"returning image response of {image_url}")

elif provider == "Stability":
bt.logging.debug(f"calling stability for {messages, seed, steps, cfg_scale, width, height, samples, sampler}")

meta = stability_api.generate(
prompt=messages,
seed=steps,
seed=seed,
steps=steps,
cfg_scale=8.0,
cfg_scale=cfg_scale,
width=width,
height=height,
samples=1,
sampler=generation.SAMPLER_K_DPMPP_2M,
samples=samples,
# sampler=sampler
)
# Process and upload the image
for artifact in meta.artifacts:
if artifact.finish_reason == generation.FILTER:
bt.logging.error("Safety filters activated, prompt could not be processed.")
elif artifact.type == generation.ARTIFACT_IMAGE:
img = Image.open(io.BytesIO(artifact.binary))
img_buffer = io.BytesIO()
img.save(img_buffer, format="PNG")
img_buffer.seek(0)
# Upload to file.io
response = requests.post('https://file.io', files={'file': img_buffer})
if response.status_code == 200:
image_url = response.json()['link']
else:
raise Exception("Failed to upload the image.")
b64s = []
for image in meta:
for artifact in image.artifacts:
b64s.append(base64.b64encode(artifact.binary).decode())

image_data["b64s"] = b64s
bt.logging.info(f"returning image response to {messages}")

else:
bt.logging.error(f"Unknown provider: {provider}")

image_data = {
"url": image_url,
"revised_prompt": image_revised_prompt,
}

synapse.completion = image_data
bt.logging.info(f"returning image response of {synapse.completion}")
return synapse

except Exception as exc:
Expand Down

0 comments on commit 28de990

Please sign in to comment.