-
-
Save dbreunig/afdd86cb560847f54359dcc3ee233766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dspy | |
| lm_kimi = dspy.LM("groq/moonshotai/kimi-k2-instruct-0905", api_key=groq_api, max_tokens=16384) | |
| dspy.configure(lm=lm_kimi, adapter=dspy.XMLAdapter()) | |
| with open('sd_prompts_200k.txt', 'r') as f: | |
| sd_prompts = f.read() | |
| class ThemeExtractor(dspy.Signature): | |
| """ | |
| Given a list of newline-separated image generation prompts, extract the top topics. | |
| A thematic category will be provided describing the type of topics to extract. | |
| """ | |
| image_gen_prompts: str = dspy.InputField() | |
| category: str = dspy.InputField() | |
| top_topics: list[str] = dspy.OutputField(desc="Topics most often present, ordered by frequency.") | |
| extractor = dspy.RLM( | |
| ThemeExtractor, | |
| max_iterations=5, | |
| max_llm_calls=8, | |
| verbose=True, | |
| ) | |
| result = extractor( | |
| image_gen_prompts=sd_prompts, | |
| category="celebrities" | |
| ) | |
| print(result.top_topics) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment