Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ Package.resolved
**/frontend/*
**/*.code-snippets
.DS_Store
.licenseignore
.licenseignore
**/*.entitlements
8 changes: 8 additions & 0 deletions Examples/ios-math-solver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
41 changes: 41 additions & 0 deletions Examples/ios-math-solver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Math Problem Solver

An iOS application that uses AWS Bedrock and Claude to solve math and physics problems from images.

## Features

- Take a photo or select an image from your photo library
- Analyze math and physics problems using Claude AI
- Get step-by-step solutions with explanations
- Secure authentication using Sign in with Apple (SIWA) and AWS STS

## Screenshot

![Math Problem Solver App Screenshot](screenshot.png)

## Technology Stack

- Swift bedrock Library for AI image analysis and problem solving
- Swift and SwiftUI for the iOS app
- Claude 3 Sonnet model for high-quality responses
- Sign in with Apple (SIWA) for authentication
- Streaming responses for real-time feedback

## How It Works

1. The app captures or selects an image containing a math or physics problem
2. The image is processed and sent to AWS Bedrock
3. Claude analyzes the problem and generates a step-by-step solution
4. The solution is streamed back to the app in real-time
5. The app displays the formatted solution with mathematical notation

## Requirements

- iOS 16.0+
- Xcode 15.0+
- AWS account with Bedrock configured
- Sign in with Apple enabled in your Apple Developer account

## License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
66 changes: 66 additions & 0 deletions Examples/ios-math-solver/Sources/AuthenticationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Bedrock Library open source project
//
// Copyright (c) 2025 Amazon.com, Inc. or its affiliates
// and the Swift Bedrock Library project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import AuthenticationServices
import Foundation
import SwiftUI

class AuthenticationManager: ObservableObject {
@Published var isAuthenticated = false // FIXME: check if the token is still valid
@Published var userId: String? = nil
@Published var error: String? = nil

var jwtToken: String? = nil

// Trigger for credential changes
@Published var credentialsUpdated = false

func signOut() {
isAuthenticated = false
userId = nil
}

func authenticate(with userIdentifier: String, identityToken: Data) {
userId = userIdentifier

// Convert identity token to string
guard let tokenString = String(data: identityToken, encoding: .utf8) else {
handleAuthError(
NSError(
domain: "AuthenticationError",
code: 1001,
userInfo: [NSLocalizedDescriptionKey: "Failed to convert identity token to string"]
)
)
return
}

self.jwtToken = tokenString

// Get AWS credentials using the Apple identity token
Task {
// Update UI on main thread
await MainActor.run {
self.isAuthenticated = true
self.error = nil
}
}
}

func handleAuthError(_ error: Error) {
self.error = error.localizedDescription
isAuthenticated = false
}
}
78 changes: 78 additions & 0 deletions Examples/ios-math-solver/Sources/Content.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Bedrock Library open source project
//
// Copyright (c) 2025 Amazon.com, Inc. or its affiliates
// and the Swift Bedrock Library project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Bedrock Library project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

let content = """
### Solution

#### Concepts Involved
This problem involves the Doppler effect, which describes the change in frequency of a wave in relation to an observer who is moving relative to the wave source. In this case, the source is a rotating sound emitter, and the observer is a microphone.

#### Given Data
- Frequency of the sound source, \\( f_0 = 1500 \\, \\text{Hz} \\)
- Radius of the circular path, \\( r = 40.0 \\, \\text{cm} = 0.4 \\, \\text{m} \\)
- The sound source is rotating in an anti-clockwise direction.

#### Steps to Solve the Problem

1. **Determine the angular velocity (\\( \\omega \\)) of the source:**

Since the source is rotating, we need to find its angular velocity. However, the problem does not provide the rotational speed directly. We will assume the tangential velocity \\( v \\) at the point of the source is given by \\( v = r \\omega \\).

2. **Calculate the Doppler shift for each position (a, b, c):**

The Doppler effect formula for sound is given by:

\\(f = f_0 \\left( \\frac{v + v_o}{v + v_s} \\right)\\)

where:
- \\( f \\) is the observed frequency.
- \\( f_0 \\) is the source frequency.
- \\( v \\) is the speed of sound in the medium.
- \\( v_o \\) is the observer's velocity relative to the medium.
- \\( v_s \\) is the source's velocity relative to the medium.

Since the observer (microphone) is stationary, \\( v_o = 0 \\).

3. **Frequency at point a:**

At point a, the source is moving towards the observer.
\\[f_a = f_0 \\left( \\frac{v}{v - v_s} \\right)\\]
where \\( v_s = r \\omega \\).

4. **Frequency at point b:**

At point b, the source is moving perpendicular to the line of sight of the observer.
\\[f_b = f_0\\]
There is no Doppler shift because the component of the velocity towards the observer is zero.

5. **Frequency at point c:**

At point c, the source is moving away from the observer.
\\[f_c = f_0 \\left( \\frac{v}{v + v_s} \\right)\\]
where \\( v_s = r \\omega \\).

6. **Compare the frequencies:**

From the Doppler effect formulas:
- \\( f_a > f_0 \\) because the source is moving towards the observer.
- \\( f_b = f_0 \\) because there is no relative motion towards or away from the observer.
- \\( f_c < f_0 \\) because the source is moving away from the observer.

Therefore, the relationship between the frequencies is:
\\(f_a > f_b = f_c\\)

### Conclusion
The frequencies perceived by the microphone are such that \\( f_a > f_b = f_c \\).
"""
Loading