Skip to content

Commit

Permalink
ais: improving thoughts
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Dec 18, 2023
1 parent 7b17882 commit 0f52df1
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 42 deletions.
30 changes: 15 additions & 15 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Chain {

val chainDesc =
p"""
The Chain thoughts enable sequential linking of multiple reasoning processes.
The Chain thought enable sequential linking of multiple reasoning processes.
- Facilitates the flow of reasoning from one thought to another.
- Ensures coherence and logical progression in the reasoning chain.
- Allows complex reasoning to be broken down into manageable segments.
Expand All @@ -16,30 +16,30 @@ import Chain._

@desc(chainDesc)
case class Chain[A, B](
`First thought or process`: A,
`Second thought or process`: B
`First thought`: A,
`Second thought`: B
)

@desc(chainDesc)
case class Chain3[A, B, C](
`First thought or process`: A,
`Second thought or process`: B,
`Third thought or process`: C
`First thought`: A,
`Second thought`: B,
`Third thought`: C
)

@desc(chainDesc)
case class Chain4[A, B, C, D](
`First thought or process`: A,
`Second thought or process`: B,
`Third thought or process`: C,
`Fourth thought or process`: D
`First thought`: A,
`Second thought`: B,
`Third thought`: C,
`Fourth thought`: D
)

@desc(chainDesc)
case class Chain5[A, B, C, D, E](
`First thought or process`: A,
`Second thought or process`: B,
`Third thought or process`: C,
`Fourth thought or process`: D,
`Fifth thought or process`: E
`First thought`: A,
`Second thought`: B,
`Third thought`: C,
`Fourth thought`: D,
`Fifth thought`: E
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import kyo.llm.ais._

@desc(
p"""
The Constrain thought involves applying constraints to the reasoning process.
- Focuses on considering specific constraints for value generation.
- Ensures that the generated values adhere to defined constraints.
The Constrain thought is a tool for applying specific constraints to the AI's reasoning process.
- The `Apply specific constraints to the value generation` field, defined as a string literal type, outlines the nature of the constraints that should govern the AI's thought generation.
- The `value` is the main focus where the AI applies the defined constraints during its reasoning or output generation.
- This mechanism is instrumental in guiding the AI to produce results within specific parameters or conditions, enhancing the relevance and precision of the output.
- Example: Constrain["Must be within ethical guidelines", EthicalReasoning] would direct the AI to ensure that the reasoning adheres to ethical guidelines.
"""
)
case class Constrain[T, C <: String](
case class Constrain[C <: String, T](
`Apply specific constraints to the value generation`: C,
value: T
)
15 changes: 15 additions & 0 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Desc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kyo.llm.thoughts.meta

import kyo.llm.ais._

@desc(
p"""
The Desc thought is designed to encapsulate a thought along with a user-defined description.
- 'desc' is a string literal type that acts as a label or a brief explanation of the thought process.
- 'value' is the actual thought or process that needs to be generated or executed.
- This class guides the LLM to focus on generating the 'value' based on the context provided by 'desc'.
- Example user code that generates this thought Desc["brainstorm something", Chain[Creative, Critical]] indicates
that the LLM should engage in a creative and critical thought chain under the theme of 'brainstorm something'.
"""
)
case class Desc[D <: String, T](desc: D, value: T)
17 changes: 17 additions & 0 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Gen.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kyo.llm.thoughts.meta

import kyo.llm.ais._

@desc(
p"""
The Gen thought is structured to facilitate the generation of a specific outcome based on a given thought process.
- The 'thought' field represents the thought process or reasoning approach that the AI should use.
- The 'value' field is the specific outcome or result that should be generated using the specified thought process.
- This thought encourages the AI to apply a particular reasoning method (as defined in 'thought') to produce a desired output (as specified in 'value').
- Example: Gen[Analysis, "Potential solutions to a problem"] would direct the AI to use analytical reasoning to generate potential solutions to the given problem.
"""
)
case class Gen[T, U](
thought: T,
value: U
)
26 changes: 26 additions & 0 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Init.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kyo.llm.thoughts.meta

import kyo.llm.ais._

@desc(
p"""
The Init thought sets foundational guidelines for the LLM's reasoning process, especially in adhering to the JSON schema.
- **Crucially, the LLM must never generate arbitrary fields and should strictly follow the provided JSON schema.**
- This thought ensures that 'value' represents specific, predefined thoughts or reasoning steps.
- Acts as a blueprint for integrating thoughts into a logical and schema-compliant reasoning pathway.
- Aims for well-structured responses that align with the user's intent and adhere to JSON formatting rules.
- Fields focus on reflecting upon past errors and strategizing to avoid them, especially in maintaining JSON schema integrity.
- Example: A 'value' containing Chain[Analysis, Synthesis] should be elaborated in accordance with the schema, without adding extraneous fields.
- **The LLM is required to ensure compliance with the JSON schema at all times.**
"""
)
case class Init[T](
`Have you failed at previous attempts to generate this json`: Boolean,
`Analysis of the previous failures`: String,
`Strategy to avoid another failure`: String,
`Elaborate on the strategy to avoid failures`: String,
`The generated json can't have new line characters`: Boolean,
`I understand I can't use new lines`: Boolean,
`Strictly adhere to the provided JSON schema without adding arbitrary fields`: Boolean,
value: T
)
46 changes: 46 additions & 0 deletions kyo-llm/shared/src/main/scala/kyo/llm/thoughts/meta/Select.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package kyo.llm.thoughts.meta

import kyo.llm.ais._

object Select {

val SelectDesc =
p"""
The Select thought facilitates the LLM's choice in focusing on particular reasoning processes.
- Enables selective expansion on specific thoughts based on relevance and significance.
- Provides flexibility in the reasoning pathway, allowing the LLM to prioritize and delve deeper into chosen thoughts.
- Encourages a targeted approach to reasoning, ensuring a more efficient and relevant output.
- The use of 'Option' in each thought or process allows for dynamic selection based on the context of the conversation.
"""
}
import Select._

@desc(SelectDesc)
case class Select[A, B](
`First thought or process`: Option[A],
`Second thought or process`: Option[B]
)

@desc(SelectDesc)
case class Select3[A, B, C](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C]
)

@desc(SelectDesc)
case class Select4[A, B, C, D](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C],
`Fourth thought or process`: Option[D]
)

@desc(SelectDesc)
case class Select5[A, B, C, D, E](
`First thought or process`: Option[A],
`Second thought or process`: Option[B],
`Third thought or process`: Option[C],
`Fourth thought or process`: Option[D],
`Fifth thought or process`: Option[E]
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kyo.llm.ais._
- Utilizes divergent thinking models from cognitive psychology.
- Applies ideation techniques and lateral thinking for novel idea generation.
- Relevant techniques: TRIZ, SCAMPER, Mind Mapping.
- Uses markdown format.
- Each 'Elaborate' field prompts the AI to provide detailed explanations and insights, enhancing the depth of the creative process.
"""
)
case class Creative(
Expand All @@ -20,15 +20,21 @@ case class Creative(

case class BrainstormIdeas(
`Generate a list of creative ideas and concepts`: String,
`Apply lateral thinking to explore new perspectives`: String
`Elaborate on the creative ideas and concepts`: String,
`Apply lateral thinking to explore new perspectives`: String,
`Elaborate on the new perspectives`: String
)

case class ExplorePossibilities(
`Consider alternative solutions and challenge existing assumptions`: String,
`Assess the feasibility and impact of different ideas`: String
`Elaborate on alternative solutions and challenged assumptions`: String,
`Assess the feasibility and impact of different ideas`: String,
`Elaborate on the feasibility and impact assessment`: String
)

case class SynthesizeConcepts(
`Integrate diverse ideas into coherent concepts`: String,
`Create innovative approaches or solutions`: String
`Elaborate on the integration of ideas into concepts`: String,
`Create innovative approaches or solutions`: String,
`Elaborate on the innovative approaches or solutions`: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kyo.llm.ais._

@desc(
p"""
The Planning thought outlines strategic steps based on analysis.
- Develops a plan of action based on analysis.
- Outlines specific measures to address the task.
- Prepares for potential challenges in implementation.
- Relevant techniques: Strategic Planning, Action Formulation.
The Planning thought outlines strategic steps based on analysis.
- Develops a plan of action based on analysis.
- Outlines specific measures to address the task.
- Prepares for potential challenges in implementation.
- Relevant techniques: Strategic Planning, Action Formulation.
"""
)
case class ActionPlanning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kyo.llm.ais._

@desc(
p"""
The Prediction thought involves forecasting future scenarios.
- Forecasts based on current understanding.
- Identifies trends for future developments.
- Considers impact of variables on outcomes.
- Relevant techniques: Forecasting Methods, Scenario Planning.
The Prediction thought involves forecasting future scenarios.
- Forecasts based on current understanding.
- Identifies trends for future developments.
- Considers impact of variables on outcomes.
- Relevant techniques: Forecasting Methods, Scenario Planning.
"""
)
case class Prediction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import kyo.llm.ais._

@desc(
p"""
The Reflection thought involves reviewing the reasoning process.
- Identifies errors or biases in reasoning.
- Considers ways to improve future responses.
- Relevant techniques: Reflective Practice, Bias Identification.
The Reflection thought involves reviewing the reasoning process.
- Identifies errors or biases in reasoning.
- Considers ways to improve future responses.
- Relevant techniques: Reflective Practice, Bias Identification.
"""
)
case class Reflection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kyo.llm.ais._

@desc(
p"""
The Synthesis thought combines disparate elements into a coherent whole.
- Integrates information for unified understanding.
- Develops hypotheses based on integration.
- Creates comprehensive summaries.
- Relevant techniques: Idea Integration, Summary Creation.
The Synthesis thought combines disparate elements into a coherent whole.
- Integrates information for unified understanding.
- Develops hypotheses based on integration.
- Creates comprehensive summaries.
- Relevant techniques: Idea Integration, Summary Creation.
"""
)
case class Synthesis(
Expand Down

0 comments on commit 0f52df1

Please sign in to comment.