-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87eed58
commit 354218f
Showing
15 changed files
with
861 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
interface OpenAIModels { | ||
object: string | ||
data: OpenAIModel[] | ||
} | ||
|
||
interface OpenAIModel { | ||
id: string | ||
object: string | ||
created: number | ||
owned_by: string | ||
permission: OpenAIModelPermission[] | ||
root: string | ||
parent?: any | ||
} | ||
|
||
interface OpenAIModelPermission { | ||
id: string | ||
object: string | ||
created: number | ||
allow_create_engine: boolean | ||
allow_sampling: boolean | ||
allow_logprobs: boolean | ||
allow_search_indices: boolean | ||
allow_view: boolean | ||
allow_fine_tuning: boolean | ||
organization: string | ||
group?: any | ||
is_blocking: boolean | ||
} | ||
|
||
interface OpenAIModelsError { | ||
message: string | ||
type: string | ||
param?: any | ||
code: string | ||
} | ||
|
||
export async function requestOpenAIModels(apiKey: string): Promise<OpenAIModels> { | ||
try { | ||
const resp = await fetch('https://api.openai.com/v1/models', { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
const result = await resp.json() | ||
if (result.error) { | ||
return Promise.reject(result.error as OpenAIModelsError) | ||
} | ||
return result | ||
} catch (e) { | ||
return Promise.reject(e) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { SvgIcon } from '../../components/SvgIcon' | ||
import { colors } from '../../res/colors' | ||
import { dimensions } from '../../res/dimensions' | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import { | ||
Pressable, | ||
StyleProp, | ||
StyleSheet, | ||
TextInput, | ||
TextStyle, | ||
View, | ||
ViewStyle, | ||
} from 'react-native' | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withTiming, | ||
} from 'react-native-reanimated' | ||
import { useSafeAreaFrame } from 'react-native-safe-area-context' | ||
|
||
const HEIGHT = 64 | ||
const TEXT_LEFT = 16 | ||
|
||
export type BottomInputProps = { | ||
style?: StyleProp<ViewStyle> | ||
index: number | ||
value: string | ||
verified: boolean | undefined | ||
verifying: boolean | ||
onChangeText: (value: string) => void | ||
} | ||
|
||
export function BottomInput(props: BottomInputProps) { | ||
const { style, index, value, verified, verifying, onChangeText } = props | ||
|
||
const { width: frameWidth } = useSafeAreaFrame() | ||
const inputWidth = frameWidth - dimensions.edgeTwice * 2 | ||
|
||
const anim = useSharedValue(0) | ||
const inputAnimStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ | ||
translateX: interpolate(anim.value, [0, 1], [4, 0], Extrapolation.CLAMP), | ||
}, | ||
], | ||
} | ||
}) | ||
const iconAnimStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ | ||
rotate: `-${anim.value * 90}deg`, | ||
}, | ||
], | ||
} | ||
}) | ||
|
||
let color = colors.black | ||
let borderColor = colors.transparent | ||
if (verified === true) { | ||
color = colors.in | ||
borderColor = colors.in | ||
} else if (verified === false) { | ||
color = colors.out | ||
borderColor = colors.out | ||
} | ||
|
||
const inputRef = useRef<TextInput>(null) | ||
const [focused, setFocused] = useState(false) | ||
const inputing = focused || value ? true : false | ||
useEffect(() => { | ||
anim.value = withTiming(inputing ? 1 : 0) | ||
}, [inputing]) | ||
|
||
return ( | ||
<View style={[styles.container, { width: inputWidth, borderColor }, style]}> | ||
<Animated.View style={inputAnimStyle}> | ||
<TextInput | ||
ref={inputRef} | ||
style={styles.text} | ||
multiline={true} | ||
numberOfLines={2} | ||
value={value} | ||
placeholder={` ${index + 1}th API Key`} | ||
returnKeyType="done" | ||
blurOnSubmit={true} | ||
onChangeText={onChangeText} | ||
onFocus={() => setFocused(true)} | ||
onBlur={() => setFocused(false)} | ||
/> | ||
</Animated.View> | ||
<Pressable | ||
style={[StyleSheet.absoluteFill, styles.rowCenter]} | ||
pointerEvents={focused ? 'none' : 'auto'} | ||
hitSlop={dimensions.hitSlop} | ||
onPress={() => { | ||
if (verifying) { | ||
return | ||
} | ||
inputRef.current?.focus() | ||
}}> | ||
<Animated.View style={iconAnimStyle}> | ||
<SvgIcon size={dimensions.iconMedium} color={color} name="vpn-key" /> | ||
</Animated.View> | ||
</Pressable> | ||
</View> | ||
) | ||
} | ||
|
||
type Styles = { | ||
container: ViewStyle | ||
text: TextStyle | ||
rowCenter: ViewStyle | ||
} | ||
|
||
const styles = StyleSheet.create<Styles>({ | ||
container: { | ||
flexDirection: 'row', | ||
height: HEIGHT, | ||
alignItems: 'center', | ||
marginBottom: dimensions.edge, | ||
paddingHorizontal: dimensions.edge, | ||
borderWidth: 1, | ||
borderRadius: dimensions.borderRadius, | ||
backgroundColor: colors.white, | ||
}, | ||
text: { | ||
flex: 1, | ||
fontSize: 15, | ||
lineHeight: 21, | ||
marginLeft: TEXT_LEFT, | ||
}, | ||
rowCenter: { | ||
flexDirection: 'row', | ||
height: HEIGHT, | ||
alignItems: 'center', | ||
paddingLeft: 8, | ||
// backgroundColor: 'green', | ||
}, | ||
}) |
Oops, something went wrong.